Fox
Fox

Reputation: 9444

How do I write this regex - word followed by number - in Java?

I know this is simple but I am not able to get it right can someone help me?

I have a string like this

 ABC 345 and XYZ 3234 MN RT X 00 AM feb17

From this string I have to take out all the numerical values except feb17. My regular expressions are not working. Can someone suggest a way to write this regex in Java?

The out put should be -

 ABC and XYZ MN RT X AM feb17

Thank You,

PS: This is not my home work. Just trying to clean up a tweet.

Upvotes: 1

Views: 262

Answers (1)

kirilloid
kirilloid

Reputation: 14304

 .replaceAll("(?<=\\s|^)\\d+(?=\\s|$)")

Upvotes: 1

Related Questions