variable inside pattern [duplicate]
var seperator = ',', group = 'red, blue';
//group.search(seperator/g) - g is not defined
group.search(/seperator/g) // looks for "seperator"
group.search('/' + seperator + '/g') // doesn't seem to find my "seperator"
And with that I'm out of ideas... How do I get my seperator
within expression?
Thanks in advance!
You need to create new regexp Object
var test = new RegExp(seperator, 'g');
group.search(test)
精彩评论