【发布时间】:2013-01-11 15:49:36
【问题描述】:
我需要编写一个正则表达式来与 JS .match() 函数一起使用。目标是检查具有多种选择的字符串。例如,如果 mystr 包含 word1 或 word2 或 word3,我想在下面的代码中返回 true
mystr1 = "this_is_my_test string_containing_word2_where_i_will_perform_search";
mystr2 = "this_is_my_test string_where_i_will_perform_search";
myregex = xxxxxx; // I want help regarding this line so that
if(mystr1.match(myregex)) return true; //should return true
if(mystr2.match(myregex)) return true; //should NOT return true
有什么帮助吗?
【问题讨论】:
-
正则表达式将检查 str 是否包含任何选项:word1、word2 或 word3?
-
是的,这就是我的意图……但所有单词都将以逗号分隔格式保存在字符串中。
标签: javascript regex