in reply to Re: Surprisingly poor regex performance
in thread Surprisingly poor regex performance

You're right, that is roughly as fast as /(?:\A|\n)(.*$pat.*\n)/omg. But it's still slower than index/rindex.

Replies are listed 'Best First'.
Re^3: Surprisingly poor regex performance
by tall_man (Parson) on Dec 14, 2004 at 21:49 UTC
    You were asking why the index/rindex is so good. It's because you're matching a pure literal string, which can use the highly-efficient Boyer-Moore search (the longer the literal string, the faster it tends to be).

    For some reason, the "^" is not being optimized properly as an anchor for "/mg" searches. Leaving it out entirely, or substituting the alternate "(?:\A|\n)" pattern, results in searches that are much faster. That seems like a bug in the optimizer.