I have a date format of
12March2018
I am trying to get a regular expression to identify the pattern using a regex expression. 1st letter must be numeric.Followed by the first 3 letters of the month. If the word which follows the numeric matches with any first 3 letter of any month it should return true. How do I get it?
Advertisement
Answer
Can you try using this regex:
/(?:Jan(?:uary)?|Feb(?:ruary)?|Mar(?:ch)?|Apr(?:il)?|May|Jun(?:e)?|Jul(?:y)?|Aug(?:ust)?|Sep(?:tember)?|Oct(?:ober)?|Nov(?:ember)?|Dec(?:ember)?)/g
In your case for identifying March
from 12March2018
, you can use as:
(?:Mar(?:ch))
Here (?:Mar)
is for identifying a month which is denote by 3 character (simple representation). And by using (?:ch)
, the full name of the month is matched or identified from string.
You can test this here.