String strs = "IP:192.168.8.216 -- [26/Feb/2001/ 10:12:12 -0500]";
String regxs = "([0-9]{1,3}\\.[0-9]{1,3}\\.[0-9]{1,3}\\.[0-9]{1,3})\\s\\-\\-\\s\\[([^\\]]+)\\]";( 要使用正则表达式已有意义的符合时要用在字符钱加双反斜杠)
PatternCompiler compiler = new Perl5Compiler();
Pattern pattern = compiler.compile(regxs);
PatternMatcher pm = new Perl5Matcher();
if(pm.contains(strs, pattern)){
MatchResult maResult = pm.getMatch();
System.out.println(maResult.group(1));
}
String regxs = "([0-9]{1,3}\\.[0-9]{1,3}\\.[0-9]{1,3}\\.[0-9]{1,3})\\s\\-\\-\\s\\[([^\\]]+)\\]";( 要使用正则表达式已有意义的符合时要用在字符钱加双反斜杠)
PatternCompiler compiler = new Perl5Compiler();
Pattern pattern = compiler.compile(regxs);
PatternMatcher pm = new Perl5Matcher();
if(pm.contains(strs, pattern)){
MatchResult maResult = pm.getMatch();
System.out.println(maResult.group(1));
}