jQuery/javascript检查字符串是否有多个子字符串 [英] jquery/javascript check string for multiple substrings
本文介绍了jQuery/javascript检查字符串是否有多个子字符串的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我需要检查一个字符串是否具有三个子字符串之一,如果是,则要实现一个功能.我知道我可以使用if (str.indexOf("term1") >= 0)
检查一个子字符串,但是除了使用此代码的多个实例之外,还有没有办法检查多个子字符串?
I need to check if a string has one of three substrings, and if yes, to implement a function. I know I can check for one substring using if (str.indexOf("term1") >= 0)
but is there a way to check for multiple substrings short of using several instances of this code?
TIA
推荐答案
if (/term1|term2|term3/.test("your string")) {
//youre code
}
这篇关于jQuery/javascript检查字符串是否有多个子字符串的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文