Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to remove ordinal value in Java?

I have Station Names like 23 St, 21 St in our mysql database.

I am applying Lucene Algorithm to search the stations in Java.

For 23 St user can give inputs like 23rd St, 23rd etc.

I want to remove Ordinals from the given inputs, like if user gives 23rd St then I want it to replace with 23 St.

So is there any way to remove ordinal value in Java?

like image 561
Deepu Avatar asked Sep 01 '25 16:09

Deepu


1 Answers

This will remove ordinals:

String s = s.replaceAll("(?<=\\d)(rd|st|nd|th)\\b", "");
like image 55
Bohemian Avatar answered Sep 04 '25 06:09

Bohemian