2013-09-28 19 views
0

我想匹配正则表达式与字符串。我的目标是找到这个词在下面的句子中。但我需要找到位置5,25和48处的单词的索引。但表达式正在返回。 “这个”也出现在“这个”中。我究竟做错了什么?匹配整个世界的正则表达式与多个字符串

var re = /(is)\b/gi, 
str = "This,is a nice job. This is, a nice world. What is this?"; 
while((match = re.exec(str)) != null){ 
console.log(match.index); 
} 

回答

4

您需要在攻防两端

var re = /\b(is)\b/gi 
+0

哦,它的工作方式与字边界匹配!谢谢。 – karthick

相关问题