tags:

views:

320

answers:

2

I want to remove any numbers from the end of a string, for example:

"TestUser12324" -> "TestUser"
"User2Allow555" -> "User2Allow"
"AnotherUser" -> "AnotherUser"
"Test123" -> "Test"

etc.

Anyone know how to do this with a regular expression in Java?

+2  A: 

Assuming the value is in a string, s:

    s = s.replaceAll("[0-9]*$", "");
Devon_C_Miller
+4  A: 

This should work for the Java String class, where myString contains the username:

myString = myString.replaceAll("\\d*$", "");

This should match any number of trailing digit characters (0-9) that come at the end of the string and replace them with an empty string.

.

brandon k