Extract date in different formats from string?

I would like to know if there is an easy way to retrieve the first date encountered from String in Java.

My program will analyze many String texts in different languages. These lines may contain a date . Due to the languages ​​(and different sources) I have so many formats to consider.

I first thought of Regex , creating one regex for each format I could find ... But there are a lot, like "Month (d) d, yyyy" or "mm / dd / yyyy" or "dd-mon- yyyy "...

So, I wanted to know if there is an easier way to extract the date from String, possibly using DateFormat, so I can convert the found date to "dd / mm / yyyy".

Thank you for your help. ^^

+4
source share
1 answer

I think the best solution is to use regex, but obviously you need to know all the possible patterns.

A (possible) way to do this is through machine learning: you can provide a set of representative examples and let the algorithm find patterns for you.

Your problem is very similar to the problem described in this article . You can try using this webapp to find a good regex for you.

, . , !

+2

All Articles