How can I use a regular expression to validate month input?

前端 未结 9 839
孤街浪徒
孤街浪徒 2020-12-11 00:31

I am setting up this example Perl snippet to validate for months in a date:

Some scenarios I want to accept are:

MM M

#!/usr/bin/perl
use str         


        
9条回答
  •  猫巷女王i
    2020-12-11 01:00

    "^(1[012]|0?[1-9])$" would be better because regular expression is assessed first one first. Let's say you want to match '12' and you write "^(0?[1-9]|1[012])$", then '1' will be picked because 0?[1-9] is taken first.

提交回复
热议问题