日期:2014-05-20 浏览次数:20610 次
import java.util.regex.Pattern; import java.util.regex.Matcher; public class Demo005 { public static void main(String[] args) { Matcher m = Pattern.compile("(\\d+)\\W+(\\d+)").matcher("朝阳区123街456栋789层987室"); while (m.find()) { System.out.print(m.group() + " "); } System.out.println(); m.reset(); while (m.find()) { for (int i = 0; i <= m.groupCount(); i++) { System.out.print("["+m.group(i) + "]"); } System.out.println(","); } } }