158>May 7 02:28:34 tcpproxy[19476]: 220.181.124.180:43603 [07/May/2012:02:28:34.204] http-in default_server/cache2 13/0/0/6/19 404 1524 - - ---- 44/44/6/0/0 0/0 {22kk.too9.com} GET /yixuanf/index.html?sid=1699 HTTP/1.1
把这个域名匹配出来吧?
把这个域名匹配出来吧?
String str = "44/44/6/0/0 0/0 {22kk.too9.com} GET /yixuanf/index.html?sid=1699 HTTP/1.1";
Pattern pattern = Pattern.compile("\\{([^}]+)");
Matcher matcher = pattern.matcher(str);
if (matcher.find()) {
System.out.println(matcher.group(1));
}稍后估计有人用replaceAll给你写个更简单的。
试试。
你:str.replaceAll(".*\\{(.*)\\}.*", "$1")
俺:str.replaceAll("[^\\{]+\\{([^}]+).+", "$1")没啥特别的玄机,只是我习惯于用排除的写法,这样减少贪婪法模式可能造成的回溯,匹配文本很长的情况下,速度会快些。
D:\文件夹\122.139.57.172\2012-05-23\yhetgame.com.txt.not200\yhetgame.com.txt
D:\文件夹\122.139.57.172\2012-05-23\yigoupai.com.txt.all\yigoupai.com.txt
D:\文件夹\122.139.57.172\2012-05-23\yigoupai.com.txt.not200\yigoupai.com.txt
D:\文件夹\122.139.57.172\2012-05-23\yiyao.tv.txt.all\yiyao.tv.txt
D:\文件夹\125.46.105.54\2012-05-23\111.111.111.111.txt