String str =
"xxx第47297章33";
String regex =
"\\d*";
Pattern p = Pattern.compile(regex);
Matcher m = p.matcher(str);
while (m.find()) {
if (!"".equals(m.group()))
System.out.println("come here:"
+ m.group());
}
打印结果:
come here:47297 come here:33
本文通过一个具体的Java代码示例介绍了如何使用正则表达式从字符串中匹配并提取数字。示例展示了如何定义正则表达式、创建Pattern对象、使用Matcher进行匹配以及遍历匹配结果。
1568

被折叠的 条评论
为什么被折叠?



