package com.xuexi;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
public class Love1 {
public static void main(String[] args) {
// 下面的例子说明如何从一个给定的字符串中找到数字串:
String line = "I love u 10000!year?";
String pattern = "(\\D*)(\\d+)(.*)";
Pattern r = Pattern.compile(pattern);
Matcher m = r.matcher(line);
if (m.find()){
// 特殊的组(group(0)),它总是代表整个表达式。
System.out.println("发现:"+m.group(0));
System.out.println("发现:"+m.group(1));
System.out.println("发现:"+m.group(2));
System.out.println("发现:"+m.group(3));
}else{
System.out.println("没发现");
}
}
}