Regular Expression Match to test for a valid year

后端 未结 14 1736
清歌不尽
清歌不尽 2020-11-29 02:27

Given a value I want to validate it to check if it is a valid year. My criteria is simple where the value should be an integer with 4 characters. I know this is

14条回答
  •  清酒与你
    2020-11-29 03:02

    Use;

    ^(19|[2-9][0-9])\d{2}$ 
    

    for years 1900 - 9999.

    No need to worry for 9999 and onwards - A.I. will be doing all programming by then !!! Hehehehe

    You can test your regex at https://regex101.com/

    Also more info about non-capturing groups ( mentioned in one the comments above ) here http://www.manifold.net/doc/radian/why_do_non-capture_groups_exist_.htm

提交回复
热议问题