I would like to remove last digit in a Java string, only if it is just one digit present.
E.g.
String text = "I am the9 number1"; // should be "I am the number"
Cases where it should do nothing:
String = "I913 am the55 number11"; // Should remain the same.
I tried this without success:
String text = "I am the1 number1";
text = text.replaceAll("^[0-9]$", "");
Didnt work. Any help?