检查var中是否含有"奶酪"或"蛋糕"?

tar*_*eld 0 javascript regex string match

如何检查变量是否包含变量?我试过检查是否.match()返回,null但是对于使用OR进行检查没有用?

Ale*_*hev 9

/cheese|cake/.test(a)

i如果你想测试不区分大小写,你可以在正则表达式的末尾添加一个


Guf*_*ffa 5

因为你只得到涉及正则表达式的答案,这里是普通的字符串操作解决方案:

var hasMatch = input.indexOf('cheese') != -1 || input.indexOf('cake') != -1;
Run Code Online (Sandbox Code Playgroud)