Beefy Boxes and Bandwidth Generously Provided by pair Networks
go ahead... be a heretic

Re: Log regexp

by hbm (Hermit)
on Aug 03, 2012 at 17:00 UTC ( #985287=note: print w/ replies, xml ) Need Help??

in reply to Log regexp

I took this:

$_ = qq{, - - [21/Apr/2012:04:35: +01 +0200] "GET /seo/vbseocp.php HTTP/1.0" 404 300 "-" "Internet Explo +rer 6.0", - - [22/Apr/2012:04:00:43 + +0200] "GET / HTTP/1.0" 200 10211 "" "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1; +)"}; m/^(\S+)\, (\S+) (\S+) \- \- \[(\d{2})\/(\w+)\/(\d{4})\:(\d{2})\:(\d{2 +})\:(\d{2})\+(\d{4})\] \"\S+\" (\d{3}) (\d+|-) \"(.*?)\" \"\.*?\"$/; print map { "[$_]\n" } $1,$2,$3,$4,$5,$6,$7,$8,$9,$10,$11,$12,$13;

And tweaked your expression down to this:

m@^(\S+?), (\S+) (\S+) - - \[(\d{2})/(\w+)/(\d{4}):\s*(\d{2}):(\d{2}): +\s*(\d{2}) \+(\d{4})\] ".*?" (\d{3}) (\d+) "(.*?)" "(.*?)"@; # 1 2 +3 4 5 6 7
  1. I made \S non-greedy, to not gobble up the comma.
  2. I changed one literal space to \s* (Your example doesn't have spaces.)
  3. Same as #2.
  4. I changed "greedy non-whitespace" (which was failing b/c the string within has whitespace) to "non-greedy non-quotes"
  5. I don't know what you intended with "(\d+|-)"...
  6. Again, non-greedy non-quotes - I think that's what you wanted.
  7. I removed the end-of-line anchor ($), because you aren't currently matching to the end.

Also note I changed the delimiter to something NOT in your content, so it doesn't need to be escaped. And I did NOT escape these other characters: -:"

Update: My numbered notes line up if you click 'download'.

Comment on Re: Log regexp
Select or Download Code
Replies are listed 'Best First'.
Re^2: Log regexp
by kazak (Beadle) on Aug 06, 2012 at 09:20 UTC
    Thanks for detailed explanation, it helped.

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://985287]
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others drinking their drinks and smoking their pipes about the Monastery: (4)
As of 2015-12-01 00:24 GMT
Find Nodes?
    Voting Booth?

    What would be the most significant thing to happen if a rope (or wire) tied the Earth and the Moon together?

    Results (788 votes), past polls