Javascript 如何使用jquery text.match()函数过滤不区分大小写的文本
我正在尝试使搜索不敏感,但它将只匹配大写字母,我希望同时使用大写和小写进行搜索。这是我的代码Javascript 如何使用jquery text.match()函数过滤不区分大小写的文本,javascript,jquery,full-text-search,Javascript,Jquery,Full Text Search,我正在尝试使搜索不敏感,但它将只匹配大写字母,我希望同时使用大写和小写进行搜索。这是我的代码 function keyup(idd){ var searchTerm = $("#tags"+idd).val(); $("#sss"+idd+' option').each(function(){ if($(this).text().match(searchTerm
function keyup(idd){
var searchTerm = $("#tags"+idd).val();
$("#sss"+idd+' option').each(function(){
if($(this).text().match(searchTerm)){
$(this).show();
}
else{
$(this).hide();
}
});
}
任何人都可以帮助我。谢谢您使用构造函数:
$(this).text().match(new RegExp(searchTerm, "i"))
使用toLowerCase()
你可以试试这样的东西,而不是火柴
if(string1.toUpperCase() == string2.toUpperCase())
使用带有忽略大小写选项的正则表达式匹配器
var regEx=new RegExp('abc','i');
console.log(regEx.test('Abc'));
console.log(regEx.test('ABC'));
console.log(regEx.test('AAA')代码>您知道您正在使用对regexp的隐式转换,并且没有转义特殊字符吗?您确定不只是想要text.toLowerCase().indexOf(searchTerm.toLowerCase())
?
if(string1.toUpperCase() == string2.toUpperCase())