Search code examples
javaregexsyslog

Error reading log file with reg expression


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?


Solution

  • 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})\]