Why doesn't [01-12] range work as expected?

后端 未结 6 1829
有刺的猬
有刺的猬 2020-11-22 03:34

I\'m trying to use the range pattern [01-12] in regex to match two digit mm, but this doesn\'t work as expected.

6条回答
  •  独厮守ぢ
    2020-11-22 04:20

    This also works:

    ^([1-9]|[0-1][0-2])$

    [1-9] matches single digits between 1 and 9

    [0-1][0-2] matches double digits between 10 and 12

    There are some good examples here

提交回复
热议问题