Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl: the Markov chain saw
 
PerlMonks  

comment on

( [id://3333]=superdoc: print w/replies, xml ) Need Help??
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":



  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or How to display code and escape characters are good places to start.
Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others having an uproarious good time at the Monastery: (6)
As of 2024-04-18 13:11 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found