MarkJ MarkJ - 3 months ago 10
Java Question

How to match this date format with a regex?

hi to all regex master out there, I know you have a work around with regards to my problem. hehe

02-May-2011


or

22-May-2011


or

2-May-2011


(dd-MMM-yyyy)
with yyyy not accepting any other characters than digit

Answer
[0-9]{1,2}/[a-zA-Z]{3}/[0-9]{4}

That's assuming that the month is a 3-letter version: eg, Jan, Feb, Mar.

Updated version to match the changes to the question:

[0-9]{1,2}-[a-zA-Z]{3}-[0-9]{4}

As has been mentioned, this won't actually validate the date, it'll just validate that the string matches the format of: 1 or 2 numbers, a dash, 3 letters, a dash, 4 numbers.