I am reading up on regular expressions and I am trying to make an expression which will match a date in the format date/month/year.
The expression will have a some but not much validation. E.g 04/17/2012 is not a valid date as there is no 17th month.
I am making the expression so that the separators can be both /, ., - and . but now I would like it to be the same separator between the components. Is there a way to adjust the regular expression so that if it matches the separator / (or any other) between the date and month then it will only match the / separator (or the one it previous matched) between the month and year?
This is my expression as it is now:
(0[1-9]|[1-2][0-9]|3[0-1]|[1-9])(/|\.( |)|-)(0[1-9]|1[0-2]|[1-9])(/|\.( |)|-)([0-9]{4}|[0-9]{2})
I will be using the expression in C#.
Backreference
\2can solve your issue:Read this article for details.