对于下面给出的表达式可用于匹配?
([0123][0-9])-([01][0-9])-([0-9]{4})
要添加此内容,可以是社会安全号码,电子邮件,日期时间等
答案 0 :(得分:2)
这可以匹配00-00-0000
给出的正则表达式
打破表达式:
([0123] -- Match 0 .. 3
[0-9]) -- Match 0 .. 9
- -- Match a dash
([01] -- Match a 0 or a 1
[0-9]) -- Match 0 .. 9
- -- Match dash
([0-9]{4}) -- Match 4 numbers in the range of 0 .. 9
至于圆括号,它们只捕捉其中的表达式,即。 ([0123][0-9])
将捕获前两个匹配件。
答案 1 :(得分:1)
我之前曾提到过RegexBuddy有多棒:
([0123][0-9])-([01][0-9])-([0-9]{4})
Match the regular expression below and capture its match into backreference number 1 «([0123][0-9])»
Match a single character present in the list “0123” «[0123]»
Match a single character in the range between “0” and “9” «[0-9]»
Match the character “-” literally «-»
Match the regular expression below and capture its match into backreference number 2 «([01][0-9])»
Match a single character present in the list “01” «[01]»
Match a single character in the range between “0” and “9” «[0-9]»
Match the character “-” literally «-»
Match the regular expression below and capture its match into backreference number 3 «([0-9]{4})»
Match a single character in the range between “0” and “9” «[0-9]{4}»
Exactly 4 times «{4}»
Created with RegexBuddy