用\s*\w+\s+\w+$空字符串替换模式:
String s = "21 Lane Street London W10 2GH";
System.out.println(s.replaceFirst("\\s*\\w+\\s+\\w+$", ""));
Run Code Online (Sandbox Code Playgroud)
生产:
21 Lane Street London
Run Code Online (Sandbox Code Playgroud)
一个简短的解释:
\s* # zero or more white space chars
\w+ # one or more alpha-nums (or underscore), specifically: [a-zA-Z0-9_]
\s+ # one or more white space chars
\w+ # one or more alpha-nums (or underscore)
$ # the end of the input
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
2886 次 |
| 最近记录: |