正则Sample(日历匹配)

正则Sample(日历匹配)

参考:Regular-expressions.Info

日历

匹配(yyyy-mm-dd)

Match a date in yyyy-mm-dd format from 1900-01-01 through 2099-12-31.

^(19|20)\d\d([- /.])(0[1-9]|1[012])\2(0[1-9]|[12][0-9]|3[01])$

匹配(m/d or mm/dd)

Match a date in m/d or mm/dd format. They exclude invalid dates such as 2/31.

Regex 1:

^(?:(0?[13578]|1[02])/(3[01]|[12][0-9]|0?[1-9])|(0?[469]|11)/(30|[12][0-9]|0?[1-9])|(0?2)/([12][0-9]|0?[1-9]))$

Regex 2:

^(?:(0?[13578]|1[02])/(3[01]|[12][0-9]|0?[1-9])|(0?[469]|11)/(30|[12][0-9]|0?[1-9])|(0?2)/([12][0-9]|0?[1-9]))$

版权所有,转载请注明出处 luowei.github.io.