in reply to A rare, insidious logfile parsing pitfall

You might have a problem if another bracket shows up later on in the line for some reason. Try this:

/^(\S+) (\S+) ([^\[]+) \[...

Of course if you're using Apache just use the CustomLog directive to define your own easily parsed log file format and be done with it.

Replies are listed 'Best First'.
Re: Re: A rare, insidious logfile parsing pitfall
by blakem (Monsignor) on Oct 28, 2001 at 14:26 UTC
    Inside a character class, you don't need to escape '['. Your class above can legally be written as [^[]. You do need to escape ']' inside a character class, however, otherwise it will be interpreted as the closing bracket of your class. So, [^a]] means "any character other than 'a' followed by a ']'."

    Its the exact opposite elsewere in the regex where an unescaped ']' is literal but '[' is not. To avoid mistakes, I usually escape both of them to get their literal interpretation no matter what their context.

    Just a clarification, not necessarily a correction.

    -Blake