-5
我不得不從字符串中的Java在Java中提取結束整數部分正則表達式來提取最後整數值
使用至REGx
,如: -
String s1="allow23"// extract 23
String s2="4code68"// extract 68
僅從結束整數(後字母表或無字母表)
我不得不從字符串中的Java在Java中提取結束整數部分正則表達式來提取最後整數值
使用至REGx
,如: -
String s1="allow23"// extract 23
String s2="4code68"// extract 68
僅從結束整數(後字母表或無字母表)
正則表達式可以是(\\d+$)
。完整的代碼示例是:
Pattern p = Pattern.compile("(\\d+)$");
Matcher m = p.matcher(str);
if (m.find()) {
int number = Integer.pareseInt(m.group(1));
}
我希望這可以成爲學習java正則表達式的良好開端。
爲什麼捕獲組?只需從組0中訪問匹配。 – nhahtdh 2013-04-09 19:44:53
到目前爲止你做了什麼? – 2013-04-09 19:08:36
[regular-expressions.info](http://regular-expressions.info)是學習正則表達式的好資源。 – Wiseguy 2013-04-09 19:12:03
@ java導師我想找到一個可以工作的正則表達式。如果你不能幫助干涉之間的干涉。 – user2263148 2013-04-09 19:12:52