【发布时间】:2012-01-03 20:39:45
【问题描述】:
我想使用 JS 函数“index()”匹配整个单词
我想就此返回-1:
var str="hello I am a string";
alert(str.index("str")); //it matches because of STRing, but don't want
编辑:但我严格地想匹配“str”,只有当它出现被两个空格包围时(但也匹配它在句子的开头/结尾)。所以\b 不适合我,因为我不想让"hello I am str. how are you?"匹配
【问题讨论】:
标签: javascript regex indexing