in reply to Superfluous subpatterns in regex alternations.

That option can match any time the regex engine has picked the first one but is forced to backtrack into the alternation. gaal gave you one example. Here are some artificial ones where the LIST option will never match but the LISTS one may:

/ (LIST|OF|LISTS) (?!S) /x / (LIST|OF|LISTS) (?(?{ $+ eq "LIST" }) (?!) ) /x

Makeshifts last the longest.

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

    Ok, I must have been suffering from a mental block on this one. I dont know how I didnt come up with these (and gaals).

    Just for the record im trying to come up with a way to make Perls regex engine optimize subpatterns of the type (LIST|OF|LITERAL|STRINGS), I had overlooked the implications of backtracking for this, and you've now set me straight. Thanks.

    ---
    demerphq