Date extraction using regex

Hi, I want to extract date from string using regex. Neither the format nor the position of date is fixed.
For instance:
NMT0929M 29Jul2009 hggjghgg NMT0929M Ad Gold Package Refresh
MT13023 18-Jan-13 hjh7788 - Change of Supplier for Packaged kl
MT13023 hjh7788 - Change of Supplier 18/Jan/13 for Packaged kl
MT13023 hjh7788 - Change of Supplier 18 january13 for Packaged kl

Thanks in advance

@Amrita Can you specify what is the exact input and output from the above example

You’re gonna have to know a format to have a chance with regex, unless you wanna go into some really complex stuff. I’ve found a nice stackoverflow topic with a whole lot of regex’ for all sorts of date formats. They’re Java, but it shouldn’t be hard to convert to VB.

You can try and check for each of them, but it might return some false positives, I can image that ‘hjh7788’ might be recognized as some date in one of these expressions.

1 Like

I want to extract date irrespective of the date format

Hi @Amrita,

You can use this regex to match all date formats you have specified in your string.

([0-3]?\d[-\/\s:_\.\*]*[JjFfMmAaSsOoNnDd][A-za-z]+[-\/\s:_\.\*]*\d{2,4})

If it doesn’t work for some other formats, kindly let me know.

Warm regards,
Nimin

2 Likes

@Amrita Refer This

1 Like

Thanks a lot.It worked

1 Like

This topic was automatically closed 3 days after the last reply. New replies are no longer allowed.