JS字符串搜索问题

时间:2013-04-16 09:02:02

标签: javascript string search substring

在另一个字符串的开头搜索字符串可以正常工作:

       if ($(this).text().search(new RegExp(filter, "i")) < 0) { ...

我还想搜索第二个单词(在逗号后面),但以下内容永远不会返回命中:

findcomma = ($(this).text().indexOf(",")+1); // plus 1 to ignore comma itself
    if ($(this).text().substring(findcomma,$(this).text().length).search(new RegExp(filter, "i")) < 0) { ...

第二句If语句的帮助将不胜感激 谢谢

1 个答案:

答案 0 :(得分:0)

我认为你的配偶()不匹配。只需将if条件重写为

即可
if (($(this).text().substring(findcomma,$(this).text().length)).search(new RegExp(filter, "i")) < 0)