Matcher.group

Exception in thread "main" java.lang.IllegalStateException: No match found

at java.util.regex.Matcher.group(Unknown Source)

Pattern p = Pattern.compile("XX");
Matcher m = p.matcher(content);
System.out.println(m.group(0));

呵呵,显示m.group(0)时添加个判断条件什么都解决了,如下:

Pattern p = Pattern.compile("XX");
Matcher m = p.matcher(content);
if(m.find()){
     System.out.println(m.group(0));
}
原文地址:https://www.cnblogs.com/iRoad/p/4065389.html