如果我有多個匹配的正則表達式像匹配:如何「的地方保持」正則表達式中的數組使用javascript
var matches = string.match(/\s*(match1)?\s*(match2)?(match3)?\s*/i);
,如果我的字符串,我測試的是這樣的:
var string = "match1 match3";
是有辦法輸出數組值:
matches[1] = "match1";
matches[2] = "";
matches[3] = "match3";
注意:我想什麼是正則表達式匹配整個事情,但「地方 - 在陣列中保持它沒有找到的匹配。
希望這是有道理的。謝謝您的幫助!
已經有一個「placeho lder連續」。例如''match2「.match(/ \ s *(match1)?\ s *(match2)?(match3)?\ s */i);'returns'[」match2「,undefined,」match2「,undefined] '[0]'是完整的正則表達式匹配,'[1] [2] [3]'是個別組 –