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"
由此我没有想法......我如何在表达中得到seperator
?
提前致谢!
答案 0 :(得分:5)
您需要创建新的regexp对象
var test = new RegExp(seperator, 'g');
group.search(test)