Reputation: 972
I have regular expressions
'\d{2}[-/.]\d{2}[-/.]\d{4}' # For dd-mm-yyyy or dd/mm/yyyy or dd.mm.yyyy.
But, it is also pulling out dd-mm.yyyy
or dd/mm-yyyy
from the string. I need a strict match for the dates i.e. dd-mm-yyyy
or dd/mm/yyyy
or dd.mm.yyyy
.
Upvotes: 2
Views: 53
Reputation: 13356
You can use this:
\d{2}([-/.])(\d{2}|[a-zA-Z]{3})\1\d{4}
([-/.])
will match -
, /
or .
as a group, and \1
anywhere in this regex will refer to the same text matched by the group.
See demo here.
Upvotes: 2