var str = "I dont have any one";
var str1 = "We dont have any one";
var str2 = "I dont have any more";
var str2 = "I dont have any two";
对于这些字符串,需要找到一个类似的reg,它应该匹配以“ I”开头且包含“一个”或“两个”的字符串。
var regx = "/^I/"; //this starts with I
var regx = "/(one|two)/"; //this match one or two
但是如何将AND与AND结合使用?
因此str1.test(regx)
应该是错误的。
只需匹配I
和之间的任何字符one
var str = "I dont have any one";
var str1 = "We dont have any one";
var str2 = "I dont have any more";
var str3 = "I dont have any two";
var regx = /^I.*(one|two)/
console.log(regx.test(str)) // True
console.log(regx.test(str1)) // False
console.log(regx.test(str2)) // False
console.log(regx.test(str3)) // True
在这里测试
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句