我需要检查字符串是否只包含一次指定的模式。 例如:
pattern = abc
qabce - returns true
qabceabcr - returns false
我尝试做这件事:
abc{1}
但如果字符串至少包含一次模式,则返回 true。
最佳答案
尝试全局 g
标志
var multipleTimes = "qabceabcr".match(/abc/g).length > 1
关于javascript - 正则表达式 - 检查字符串是否只包含一次模式,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40828167/