var str = "hello world ! hello coder!" ; //查找‘HELLO’是否存在,找不到返回null var reg = new RegExp('HELLO','i') ; var isHas = str.match(reg); console.log(isHas); //打印结果: ["hello", index: 0, input: "hello world ! hello coder!", groups: undefined]
var str="Hello world!"; //查找"Hello" var patt=new RegExp('HELLO','i') ; var result=patt.test(str); console.log(result) // true
如上两种,用正则new RegExp,test/match查找可以实现,不区分大小写
标签:js,查找,大小写,str,new,var,RegExp,hello From: https://www.cnblogs.com/heibaiqi/p/17318301.html