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
See Question&Answers more detail:os