对匹配/不匹配的正则表达式返回true / false [英] Return true/false for a matched/not matched regex

查看:110
本文介绍了对匹配/不匹配的正则表达式返回true / false的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在Javascript上有这个正则表达式

I have this regex on Javascript

var myS = "00 - ??:??:?? - a";
var removedTL = myS.match(/^(\d\d) - (\?\?|10|0\d):(\?\?|[0-5]\d):(\?\?|[0-5]\d) - (.*)/);

如果 myS 不是那种格式,否则为真。

and I need to return "false" if myS is not in that format, true otherwise.

我的意思是:

var myS = "00 - ??:??:?? - a";  // TRUE
var myS = "00 - ??:?:?? - a";   // FALSE

如何检查正则表达式是否与字符串匹配?

how can I check if the regex has matched the string or not?

推荐答案

匹配方法将返回 null 如果没有匹配。

The match method will return null if there is no match.

这篇关于对匹配/不匹配的正则表达式返回true / false的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆