Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/391.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/string/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript JS字符串搜索问题_Javascript_String_Search_Substring - Fatal编程技术网

Javascript JS字符串搜索问题

Javascript JS字符串搜索问题,javascript,string,search,substring,Javascript,String,Search,Substring,在另一个字符串的开头搜索一个字符串可以使用以下命令: if ($(this).text().search(new RegExp(filter, "i")) < 0) { ... if($(this).text().search(newregexp(filter,“i”)))

在另一个字符串的开头搜索一个字符串可以使用以下命令:

       if ($(this).text().search(new RegExp(filter, "i")) < 0) { ...
if($(this).text().search(newregexp(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) { ...
findcomma=($(this).text().indexOf(“,”)+1);//加1忽略逗号本身
如果($(this).text().substring(findcomma,$(this).text().length).search(newregexp(filter,“i”))小于0){。。。
第二个If语句的帮助将不胜感激
谢谢

我想你错配了parantises
()
。只需将if条件重写为

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

到底是什么问题?也许第二个单词与
过滤器不匹配
regexp…顺便说一句,如果要提取用逗号分隔的字符串中的单词,应该使用
$(this).text().split(“,”[i]
(第一个单词i=0,第二个单词i=1,…)与其说我想提取字符串,不如说我知道字符串在那里。我可以在第一个单词OK中找到字符串,但在第二个字符串(逗号后)中找不到。感谢您的快速响应!因此,您能否添加一个jsfiddle示例,因为我没有看到任何代码错误…jsfiddel是我的新示例-将在回家后整理如何执行此操作-同时,感谢您的帮助…我提供了一个示例,说明它找到了正确的单词:。stf的重写有相同的错误(它找不到字符串)