import java.util.regex.Matcher;
import java.util.regex.Pattern;
public class zhengz {
public static void main(String[] args) {
String line = "This order was placed for QT3000 ok?";
String pattern = "QT(\\d+).ok?";
Pattern r = Pattern.compile(pattern);
Matcher m = r.matcher(line);
System.out.println(m.find());
System.out.println(m.groupCount());
System.out.println(m.group(1));
System.out.println(m.replaceFirst("QT8000 ok!"));
}
}
输出:
true
1
3000
This order was placed for QT8000?