in reply to Re^2: Analyzing regular expression performance
in thread Analyzing regular expression performance

Changing the $sp regex to (?:\s*) cut runtime to almost nothing, so it looks like that's where my problem is.

I do need to allow comments anywhere in the string, though -- including having comments right after comments. Is there a cleaner way of doing that?

---
A fair fight is a sign of poor planning.

Replies are listed 'Best First'.
Re^4: Analyzing regular expression performance
by grinder (Bishop) on May 12, 2006 at 19:04 UTC

    I do think you are insane to parse SQL with regular expressions, but if you are brave and insist on this approach, I would suggest a multi-pass approach.

    Write one pattern that strips out comments. Write another pattern to coalesce blanks into a single blank. Then you will find that writing a third pattern to pick apart an expression becomes much easier. At least you won't need so many nested 0-or-many groupings -- that is what is killing your performance.

    I tried to run your code and it ate up all available memory... I do no think this approach will scale.

    • another intruder with the mooring in the heart of the Perl