in reply to Analyzing regular expression performance

to analyse a regex, you can use YAPE::Regex::Explain.

update: one example: perl -MYAPE::Regex::Explain -e 'print YAPE::Regex::Explain->new(qr/(<a\s(?:[^>](?!href))*href\s*)(&(&[^;]+;)?(?:.(?!\3))+(?:\3)?)([^>]+>)/)->explain'

For the performance, one thing that comes to my mind is the /o qualifier to compile once only. And if You still suffer from perfomance issues, You might want to use a debugger and/or profiler. But in that case, maybe You should first try to 'divide and conquer' the regexp into a few smaller ones.

Replies are listed 'Best First'.
Re^2: Analyzing regular expression performance
by duff (Parson) on May 12, 2006 at 18:37 UTC
    For the performance, one thing that comes to my mind is the /o qualifier to compile once only

    Yikes! Don't ever recommend that. It's rarely needed and causes more trouble than it is worth. Perl already does optimizations for patterns that contain no variables and for patterns that do contain variables that don't vary over the lifetime of the code in which the pattern appears, so /o won't buy you anything there. If you really need the "compile once" idea, just use qr/.../

      what You say makes sense to me. At least the 'wont buy you anything' part. What I dont understand: how can the /o cause trouble?