var str="abcbb"; console.log(str.indexOf("ca")); if(str.indexOf("a") !=-1){ console.log("包含") } console.log(str.search("a")) if(str.search("a") !=-1){ console.log("包含") } var reg = RegExp(/b/); console.log(str.match(reg)) if(str.match(reg)){ // 包含 } console.log(reg.test(str));//true if(reg.test(str)){ //包含 } console.log(reg.exec(str)) if(reg.exec(str)){ console.log("包含") }else{ console.log("不包含") }
来源:https://blog.csdn.net/qq_34794885/article/details/103668380
search与indexOf的区别
https://blog.csdn.net/weixin_33890526/article/details/88759700
https://www.cnblogs.com/52cik/p/js-string-search.html