测试找到正则匹配内容的Java方法:
public void testZZ(String regex,String targetStr){
Pattern pattern = Pattern.compile(regex);
Matcher m = pattern.matcher(targetStr);
while (m.find()) {
for (int i=0;i< m.groupCount();i++) {
System.out.println("Found value: " + m.group(i) );
}
}
}
//例子
//String targetStr ="--<xxx>--<yyyy>---sdf<>---<----";
//Pattern pattern = Pattern.compile("<(.*?)>");
结果:
Found value: <xxx>
Found value: <yyyy>
Found value: <dsf>
Found value: <>