theAcolyte has asked for the wisdom of the Perl Monks concerning the following question:
I've got a regEx which is working fine, but it seems, somehow, inelegant. I've been pouring through documentation to find a better way to write this, but I haven't come up with anything yet.
While I've wrapped my mind around the basics, I'm always striving to get better, so I thought I'd ask: is there a better way to do this?
Here is the (single line) I'm matching against:
[Tue Apr 20 04:51:19 2004] [error] [client 68.103.45.137] File does no +t exist: /home/virtual/site6/fst/var/www/html/robots.txt
And here is my regEx:
\[client[\w\s.]{12,16}\](.*?$)
$1 captures everything which is the actual error, in this examples case "File does not exist .... " to the end.
I had thought there must be a way to say "match the very last ] you find, til the end of the line, but I haven't been able to figure it out. Just seems wasteful to me to have to match all that client 102.102.102.102 stuff to grab the part I actually want.
So, anyone care to enlighten me on the more elegant solution? Eagerly awaiting your Monkish reponses ...
theAcolyte
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Is there a better way to write this RegEx?
by japhy (Canon) on Apr 20, 2004 at 12:55 UTC | |
by sgifford (Prior) on Apr 20, 2004 at 15:56 UTC | |
by theAcolyte (Pilgrim) on Apr 20, 2004 at 13:06 UTC | |
by japhy (Canon) on Apr 20, 2004 at 13:10 UTC | |
|
Re: Is there a better way to write this RegEx?
by pbeckingham (Parson) on Apr 20, 2004 at 13:16 UTC |