开发者

Regex Help - Formatting \d{4}-0[1-9]|1[0-2].*

开发者 https://www.devze.com 2023-02-16 01:51 出处:网络
I need to enforce a format for a field \"2011-12 whatever else after\" The h开发者_如何学编程yphen needs to be included between the digits, and no spaces until after the second digit in the year. I t

I need to enforce a format for a field "2011-12 whatever else after"

The h开发者_如何学编程yphen needs to be included between the digits, and no spaces until after the second digit in the year. I think the hyphen is throwing this off. I've played with Expresso but to no avail.

\d{4}-0[1-9]|1[0-2].* What's wrong with this?


Try ^\d{4}-(1[0-2]|0[1-9])\s

If you don't need the trailing space remove \s.

This matches:

Sequence: match all of the following in order
  BeginOfLine
  Repeat
    Digit
    4 times
  -
  CapturingGroup
    GroupNumber:1
    OR: match either of the following
      Sequence: match all of the following in order
        1
        AnyCharIn[ 0 to 2]
      Sequence: match all of the following in order
        0
        AnyCharIn[ 1 to 9]
  WhiteSpaceCharacter


Unless I am misunderstanding the requirements, this should work fine:

^2011-12.*

0

精彩评论

暂无评论...
验证码 换一张
取 消