Java正则表达式删除所有尾随数字? [英] Java regex to remove all trailing numbers?
本文介绍了Java正则表达式删除所有尾随数字?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想从字符串末尾删除任何数字,例如:
I want to remove any numbers from the end of a string, for example:
"TestUser12324" -> "TestUser"
"User2Allow555" -> "User2Allow"
"AnotherUser" -> "AnotherUser"
"Test123" -> "Test"
等。
任何人知道如何使用Java中的正则表达式执行此操作吗?
Anyone know how to do this with a regular expression in Java?
推荐答案
这应该适用于Java String类,其中myString包含用户名:
This should work for the Java String class, where myString contains the username:
myString = myString.replaceAll("\\d*$", "");
这应匹配任何数字的结尾数字字符(0-9)字符串并用空字符串替换它们。
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.
。
这篇关于Java正则表达式删除所有尾随数字?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文