假设我有一个由包含特殊字符的单词组成的列表:
one
<two></two>
three#
$four
etc.
我想查找列表中包含特定字母的所有单词,
我尝试过使用
var myList = "<one></one> $two three#";
var myRegex = /\bMYWORD[^\b]*?\b/gi;
alert(myList.match(myRegex));
但这不适用于特殊字符..
不幸的是,我是 JavaScript 新手,我不知道创建列表的最佳方法是什么
并分隔列表中的单词..
最佳答案
因此,根据您的输入,这可以解决问题:
var myList = "<one></one> $two three#";
var items = myList.split(' ');
$('#myInput').on('input',function(){
var matches = [];
for(var i = 0; i < items.length; i++) {
if(items[i].indexOf(this.value) > -1)
matches.push(items[i]);
}
$('#myDiv').text(matches.join(','));
});
是this你想要什么?
关于javascript - 查找包含特定字母和特殊字符的所有单词,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25628977/