[英]Java regex to remove all trailing numbers?
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? 任何人都知道如何使用Java中的正则表达式执行此操作?
This should work for the Java String class, where myString contains the username: 这应该适用于Java String类,其中myString包含用户名:
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. 这应该匹配字符串末尾的任意数量的尾随数字字符(0-9),并用空字符串替换它们。
. 。
假设值在字符串中,s:
s = s.replaceAll("[0-9]*$", "");
这应该是正确的表达方式:
(.+[^0-9])\d*$
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.