4
I’m trying to extract a date from a string, but I’m not getting it.
Example:
String stringQualquer = "um teste qualquer12/02/1998 19/09/1880 Nulo";
I want to pick up the first date of this example "12/02/1998".
I tried that, but it didn’t work:
^(\\d{2}\\/\\d{2}\\/\\d{4})
Only complementing, if the
String
contains only valid dates, regex resolves, but if it has things like31/04/2018
(April 31, which is an invalid date), regex will give a false positive. I suggest that after the date is obtained fromString
, it is also validated using the Java date Apis as explained in this answer: https://answall.com/a/187296/112052– hkotsubo