public class TestPatternFind {
public static void main(String[] args) {
String testString = "xxxxxxx1234xxxxxxx5678xxxxx12xxx1xxx";
Matcher matcher = Pattern.compile("//d+").matcher(testString);
while(matcher.find()){
System.out.println( testString.substring(matcher.start(), matcher.end()) );
}
String testString2 = "${object.property}";
Matcher matcher2 = Pattern.compile("^//$//{([a-zA-Z][a-zA-Z0-9//.]*)//}$").matcher(testString2);
if(matcher2.matches()){
System.out.println(matcher2.group(0));//抓取整个匹配字符串
System.out.println(matcher2.group(1));//抓取在匹配字符串中,匹配正则表达式中()部分的字符串
}
}
}
|