in reply to Superfluous subpatterns in regex alternations.

Good point. As long as it's the only clause in the regex, you're right that they'd be equivalent.

But to issue the warning you want, the regex engine would have to post-process the regex, to make sure it IS equivalent, and no one slipped in anything after the closing ).

And even then, how would you deal with qr//?

Given:

$re=qr/(LIST|OF|LISTS)/;
you couldn't optimize $re to /(LIST|OF)/, since you don't know where it will be used, right?

Mike

Replies are listed 'Best First'.
Re^2: Superfluous subpatterns in regex alternations.
by demerphq (Chancellor) on Jan 03, 2005 at 12:55 UTC

    Yes, qr// does provide some problems here. But actually post processing the regex isnt a problem, as in principle thats exactly what I want to do. The objective is to turn patterns of the type (LIST|OF|LISTS) into a trie or DFA depending on the circumstances. If this is to be a silent optimisation then scanning the regex once its compiled will become necessary to identify points in the pattern where its possible. OTOH, introducing a new (?...:) type would reduce the costs involved, but would only make the optimisations available to new code. But this thread has given me lots of angles to consider. Thanks all.

    ---
    demerphq