我在 Javascript 上有这个正则表达式
var myS = "00 - ??:??:?? - a";
var removedTL = myS.match(/^(\d\d) - (\?\?|10|0\d):(\?\?|[0-5]\d):(\?\?|[0-5]\d) - (.*)/);
如果 myS
不是那种格式,我需要返回“false”,否则返回 true。
我的意思是:
var myS = "00 - ??:??:?? - a"; // TRUE
var myS = "00 - ??:?:?? - a"; // FALSE
如何检查正则表达式是否匹配字符串?
最佳答案
这里更合适的函数可能是RegExp.test
,explicitly gives you true or false .
console.log(/lolcakes/.test("some string"));
// Output: false
console.log(/lolcakes/.test("some lolcakes"));
// Output: true
关于javascript - 为匹配/不匹配的正则表达式返回 true/false,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7052797/