Bonjour! (feeling international today)

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


In reply to Is there a better way to write this RegEx? by theAcolyte

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.