Reputation: 1
I have some log file text like this:
21.125.155.111 - - [01/Jan/2012:12:07:48 +0530] "GET /digital-cameras/digital-camera/sony-qx-dsc-qx100-point-shoot-digital-camera-black.html HTTP/1.1" 200 1470 "Mozilla/5.0 (Windows; U; Windows NT 6.1; en-US; rv:1.9.2.17) Gecko/20110420 Firefox/3.6.17" "-"
and my pattern is:
"(?<ip>[\\d\\.]+)(.+)\\\"(?<verb>\\w+) (?<address>.+) (?<protocol>[HTTPS]+)/(?<version>.+?)\\\"\\s(?<status>\\d+)\\s(?<time>\\d+)\\s\\\"(?<useragent>.*)\\\"\\s(.*)"
But I get the above PatternSyntaxException when I try to compile the pattern.
It works perfectly in C# but gives exception in Java 1.6.
Upvotes: 0
Views: 90
Reputation: 75252
What you've got there is a Java bug that produces an erroneous error message. Java 6 doesn't support named groups, so when the regex compiler sees (?<
, it leaps to the conclusion that you're trying to create a lookbehind. It should wait until it reads one more character before doing anything, and if the next character is anything but =
or !
, it should throw an exception with a more general explanation, like "unknown group construct".
But the solution to your problem is either to upgrade to Java 7, or to use old fashioned numbered groups instead of the named kind.
Upvotes: 3