Using alternation and grouping constructs

后端 未结 2 449
被撕碎了的回忆
被撕碎了的回忆 2021-01-24 07:52

Originally I wanted a regex parsing month numbers. At first I came up with the following regex:

^([1-9]{1})|(1[012])$

and it matched any positi

2条回答
  •  佛祖请我去吃肉
    2021-01-24 08:22

    The alternation operator has the lowest precedence of all regex operators.

    The difference between the two regular expressions, interpreted literally, is this:

    ( [BEGIN]([1-9]) )    OR    ( (1[012])[END] )
    

    vs

    [BEGIN] ( [1-9]    OR    1[012] ) [END]
    

提交回复
热议问题