private static String pattern = "^([\d.]+) (\S+) (\S+) \[([\w:/]+\s[+\-]\d{4})\] "(.+?)" (\d{3}) (\d+|-) "([^"]+)" "([^"]+)"";
//静态方法获取Pattern对象
private static Pattern p = Pattern.compile(pattern);
//line是待验证的字符串
Matcher matcher = p.matcher(line);
//匹配成功
if (matcher.matches()){
...
}