フィールドから値を取得し、一致しないテーブルの行を非表示にするライブフィルターをJavaScriptで作成しました。
これに使用する正規表現は非常に単純です:/ inputValue / i
これはうまく機能しますが、順番に並んでいる文字にのみ一致します。例えば:
inputValue = test
string to match = this is a test sentence
この例は一致しますが、私が試した場合:
inputValue = this sentence
string to match = this is a test sentence
入力値が乱れているため、これは一致しません。
順序は正しいが単語をスキップできる正規表現を作成するにはどうすればよいですか?
現在使用しているループは次のとおりです。
for (var i=0; i < liveFilterDataArray.length; i++) {
var comparisonString = liveFilterDataArray[i],
comparisonString = comparisonString.replace(/['";:,.\/?\\-]/g, '');
RE = eval("/" + liveFilterValue + "/i");
if (comparisonString.match(RE)) {
rowsToShow.push(currentRow);
}
if(currentRow < liveFilterGridRows.length - 1) {
currentRow++;
} else {
currentRow = 0;
}
}
お時間をいただき、ありがとうございました。
クリス