标签:style blog color ar java sp div log bs
package com.benywave; import java.util.regex.Matcher; import java.util.regex.Pattern; public class Test { public static void main(String[] args) { String str = "急救电话 112"; Pattern pattern = Pattern.compile("[0-9]{1,}"); Matcher matcher = pattern.matcher((CharSequence) str); while (matcher.find()) { if (!"".equals(matcher.group())) System.out.println("截取字符串中的数字为:" + matcher.group()); } } }
输出结果: 截取字符串中的数字为:112
标签:style blog color ar java sp div log bs
原文地址:http://www.cnblogs.com/sphere/p/4019670.html