我需要編寫一個正則表達式來使用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? – Diego
是的,這是我的意圖......但所有的單詞都會以逗號分隔格式的字符串。 – abdfahim