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

That would definitely explain at least some of it. The $sp and $words regexes posted above have that structure.

---
It's all fine and dandy until someone has to look at the code.

Replies are listed 'Best First'.
Re^3: Analyzing regular expression performance
by Sprad (Hermit) on May 12, 2006 at 16:54 UTC
    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.

      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