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
时间: 2024-10-11 13:03:36