Reputation: 1141
I have a value like
V = "Val1,Val2;Val3"
In this case If I need to separate "Val1,Val2" from V I am using this
var newVal = V.substr(0, V.indexOf(";"));
But this case is faling for some value like this
V = "Val4;Val1,Val2;Val3"
Any idea how to take only the value which having "," and remove all other character which is separated by ";"
Upvotes: 0
Views: 72
Reputation: 10458
use the regex
\w+,\w+
to solve this
function match(str){
return str.match(/\w+,\w+/g);
}
console.log(match('a;b,c;d'));
console.log(match('a,b;c'));
Upvotes: 5