Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我必须从java中的字符串中提取结束整数部分
在java中使用正则表达式
像:-
String s1="allow23"// extract 23 String s2="4code68"// extract 68
仅从末尾开始的整数(在字母表或无字母表之后)
正则表达式可以是(\\d+$). 完整的代码示例是:
(\\d+$)
Pattern p = Pattern.compile("(\\d+)$"); Matcher m = p.matcher(str); if (m.find()) { int number = Integer.pareseInt(m.group(1)); }
我希望这可以成为您学习 Java 正则表达式的良好开端。