In the standard apache error log file format, we have:
[Mon Jun 17 23:09:46 2002] [error]usage: tie @array, Tie::File, filena +me, [option => value]... at d:/httpd/apache/perl/velog.pl line 16 [Mon Jun 17 23:24:44 2002] [error] [client 127.0.0.1]File does not exi +st: d:/httpd/apache/htdocs/kjh
I would like to add a <BR> tag after the blocks of [ ] but before the error begins, like this:
[Mon Jun 17 23:09:46 2002] [error] usage: tie @array, Tie::File, filename, [option => value]... at d:/htt +pd/apache/perl/velog.pl line 16 [Mon Jun 17 23:24:44 2002] [error] [client 127.0.0.1] File does not exist: d:/httpd/apache/htdocs/kjh
My first try was to just go with s/^(\[.*\])/$1<br>/; which worked all too well. . The problem was that it was matching everything up to and including any ]'s in the error string as well. After reading Ovid's writeup(Thank you for Death to Dot Star!), I changed my regex to s/^(\[^]])/$1<br>/;. That change fixed things too much in the other way (only capturing the first [ ]). Now, I've come up with what seems to me to be very complicated.
s/^ #start of string ( #start capture (?: #begin non-capturing repeating \[ #literal [ [^]]* #anything that isn't a ] ]\s* #ending ] and optional spaces )+ #end non capturing repeating ) #end capture / #end match $1<br>/gx;
Iwas surprised at myself for coming up with this. I would very much appreciate any suggestions you might have to simplify this beast. Have I missed anything (I'm very good at missing the good points)?

Thank you.


In reply to Help with Regex for Apache Error Logs by coolmichael

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.