ITeye博客

java利用正则截取字符串中的数--学习笔记

rfheh · 2011-10-17 11:19 · 编程语言 · Java · 正则表达式 · String · Markdown

java利用正则截取字符串中的数字 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());
}

只能输入整数或小数的正则表达式 "^[0-9]+([.]{1}[0-9]+){0,1}$" :cry:

评论(0)

暂无评论。

评论功能维护中,当前仅展示历史评论。