下面代码一直报错,实在是搞的头晕了,哪位大侠帮忙看下错在哪啊!!!!!
代码:
String str = "ttt_aaaa_123232.log";
String regStr = "ttt_(.*)_\\d\\.log";
Pattern pattern = Pattern.compile(regStr);
Matcher matcher = pattern.matcher(str);
String sr = matcher.group(1);
System.out.println(sr);
是想得到aaaa的部分
错误信息:
Exception in thread "main" java.lang.IllegalStateException: No match found
at java.util.regex.Matcher.group(Unknown Source)
at test.hl.TestApp.main(TestApp.java:95)
------解决方案--------------------------------------------------------
- Java code
String str = "ttt_aaaa_123232.log"; String regStr = "ttt_(.*)_\\d*\\.log"; Pattern pattern = Pattern.compile(regStr); Matcher matcher = pattern.matcher(str); while(matcher.find()){ System.out.println(matcher.group(1)); }
------解决方案--------------------------------------------------------