Skip to content
Advertisement

Strip date from String with junk data – Java

I need to know if there is anyway to strip the date alone from text like below using java. I am trying to find something more generic, but couldn’t get any help, As the input varies.

Some example inputs:

JavaScript

or

JavaScript

or

JavaScript

I have seen some code which works for trailing junk characters but couldn’t find anything if the date is in between the string and if it varies to different formats.

Advertisement

Answer

We could use String#replaceAll here for a regex one-liner approach:

JavaScript

This prints:

JavaScript
User contributions licensed under: CC BY-SA
5 People found this is helpful
Advertisement