[Solved] Javascript SUBSTR


Basic regular expression

var str = "radio_3_5";
console.log(str.match(/^[a-z]+_\d+/i));

And how the reg exp works

/       Start of reg exp
^       Match start of line
[a-z]+  Match A thru Z one or more times
_       Match underscore character
\d+     Match any number one or more times
/       End of Reg Exp
i       Ignores case

Or with split

var str = "radio_334_1234";
var parts = str.split("_");
var result = parts[0] + "_" + parts[1];

Or even crazier (would not do)

var str = "radio_334_1234";
var result = str.split("_").slice(0,2).join("_");

solved Javascript SUBSTR