如果我使用一個新的正則表達式對象是這樣的:正則表達式來找到特定的神經末梢
for(i=0; i < aray.length; i++){
searchTerm = new RegExp("\\b" + aray[i] + "(e\\b)", "gi");
word = testText.match(searchTerm);
if(word){
found.push(word);
}
}
所得陣列「找到」包含{一,三,片}。 但是如果我改變到:
for(i=0; i < aray.length; i++){
searchTerm = new RegExp("\\b" + aray[i] + "(e\\b)");
word = testText.match(searchTerm, "gi");
if(word){
found.push(word);
}
}
所得陣列「找到」包含{一個,例如,三個,即,片,電子}。附加e從哪裏來?
此外,搜索以「e」或「es」或「et」結尾的單詞的最佳方法是什麼?
附加'e's來自'found.push(word)'行。基本上,匹配返回一個不是布爾值的匹配數組。使用'test'方法來獲得布爾值。 – Pete
@你是對的。閱讀更多關於[JavaScript String match()方法](http://www.w3schools.com/jsref/jsref_match.asp) – Braj