I'm trying to write a regular expression to validate a date in Unix. The regex that matches a date in the usual format is mm/dd/yy
For example, it should match 03/20/98 or 11/08/89 but not 13/40/99
I managed to find the answer on Regular Expression to match valid dates but the expression is not working on UNIX.
Below regex is not working when I tried to validate the date
echo '12/01/2014' | grep '^((((0[13578])|([13578])|(1[02]))/)|(((0[469])|([469])|(11))/)|((2|02)/))[/]\d{4}$|^\d{4}$'
No matches
echo '2/1/2014' | grep '^((((0[13578])|([13578])|(1[02]))/)|(((0[469])|([469])|(11))/)|((2|02)/))[/]\d{4}$|^\d{4}$'
No matches
Copyright Notice:Content Author:「user3317828」,Reproduced under the CC 4.0 BY-SA copyright license with a link to the original source and this disclaimer.
Link to original article:https://stackoverflow.com/questions/22135276/date-regular-expression-in-unix