java 正在表达式
package com.mcs;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
public class Regular {
static String reg = "(124.31.217.208).*(GET).*tmwv=(5.4.6)&utms=(52)*";
static String str = "124.31.217.208 - - [11/Dec/2013:10:00:03 +0800] \"GET /__utm.gif?utmwv=5.4.6&utms=52&utmn=1340277287&utmhn=easternmiles.ceair.com&utmcs=utf-8&utmsr=1280x768&utmvp=1243x551&utmsc=16-bit&utmul=zh-cn&utmje=1&utmfl=11.9%20r900&utmdt=%E8%88%AA%E7%8F%AD%E9%80%89%E6%8B%A9%20-%20%E4%B8%AD%E5%9B%BD%E4%B8%9C%E6%96%B9%E8%88%AA%E7%A9%BA%E5%85%AC%E5%8F%B8&utmhid=1827326032&utmr=0&utmp=%2Fflight%2FLXA-KMG-140109_CNY.html HTTP/1.1\" 200 52 easternmiles.ceair.com:80";
public static void main(String srg[]) throws Exception {
System.out.println(reg);
Pattern p = Pattern.compile(reg);
Matcher m = p.matcher(str);
while (m.find()) {
System.out.println(m.group(1));
System.out.println(m.group(2));
System.out.println(m.group(3));
System.out.println(m.group(4));
}
}
}
网友评论