Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/regex/16.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中为正则表达式数组使用replace_Javascript_Regex_Replace_Str Replace - Fatal编程技术网

如何在javascript中为正则表达式数组使用replace

如何在javascript中为正则表达式数组使用replace,javascript,regex,replace,str-replace,Javascript,Regex,Replace,Str Replace,所以我想输入一个字符串,测试该字符串中可能包含的一系列可能的单词,如果这些单词中有任何一个出现在字符串中,我想用一个特定的单词替换它们,在本例中是“is” 函数替换_是(字符串){ var exps=[/looks/,/executes/,/seem/,/feels/]; 对于(i=0;i我不相信string.replace修改string,所以您应该: return string.replace(exps[i], "is"); return string.replace(exps[i], "

所以我想输入一个字符串,测试该字符串中可能包含的一系列可能的单词,如果这些单词中有任何一个出现在字符串中,我想用一个特定的单词替换它们,在本例中是“is”

函数替换_是(字符串){
var exps=[/looks/,/executes/,/seem/,/feels/];

对于(i=0;i我不相信string.replace修改string,所以您应该:

return string.replace(exps[i], "is");
return string.replace(exps[i], "is");