Reputation:
I am trying to read a log file with the content look like this:
127.0.0.1 - - [17/OCT/2009:00:02:14 0000] GET xxxxxx xxxx xxx
I tried the following reg exp and I am getting ERROR: Unclosed group near index 90
regex = (\d+\.\d+\.\d+\.\d+)\s-\s-\s\[(\d+)/(\w{3})/(\d{4}):(\d{2}):(\d{2}):(\d{2})\s(\d{4}\)].*
Can someone help me?
Upvotes: 1
Views: 328
Reputation: 1531
^\d+\.\d+\.\d+\.\d+\s-\s-\s\[\d{2}\/[A-Z]{3}\/\d{4}:\d{2}:\d{2}:\d{2}\s\d{4}]\sGET\s(.{6}\s.{4}\s.{3})$
Upvotes: 0
Reputation: 195
[ and ] are special characters. That's what it means by unclosed group. Depending on your flavor of regex, you'll need to put either 1 \ or 2 \ in front of each bracket.
regex = (\d+.\d+.\d+.\d+)\s-\s-\s[(\d+)/(\w{3})/(\d{4}):(\d{2}):(\d{2}):(\d{2})\s(\d{4})].*
Upvotes: 0
Reputation: 3780
First, escape [ and ] with backslahes. They have special meaning in regexps.
Upvotes: 0
Reputation: 6757
You forgot escaping some chars:
^(\d+\.\d+\.\d+\.\d+)\s-\s-\s\[(\d+)\/(\w{3})\/(\d{4}):(\d{2}):(\d{2}):(\d{2})\s(\d{4})\]
Upvotes: 2
Reputation: 33092
I think the "[" and "]" should be escaped: [[]
and []]
or \[
and \]
.
For Java:
java.util.regex.Pattern.compile("(\\d+.\\d+.\\d+.\\d+)\\s-\\s-\\s\\[(\\d+)/(\\w{3})/(\\d{4}):(\\d{2}):(\\d{2}):(\\d{2})\\s(\\d{4})\\].*")
Upvotes: 1