我有这个字符串:
testString = "child 4 to 10 years old";
如何检查字符串是否包含两个(或更多)数字?
testString.match("??")
谢谢!
最佳答案
如果字符串包含至少两个数字,这将找到一个匹配项。
testString.match(/(?:.*?\b\d+\b){2}/)
或
/(?:.*?\b\d+\b){2}/.test(str);
或
如果你还想处理小数,那么试试这个,
/(?:.*?\b\d+(?:\.\d+)?\b){2}/.test(str);
关于Javascript:如何检查字符串中是否存在两个数字? (正则表达式),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31432551/