in reply to Re^4: How to replace greedy alternation?
in thread How to replace greedy alternation?

How wonderful ! And another regex trick learned :-)

Though it goes bloomin' berserk backtrackin' when all four of 'abcd' are not present ! The following tweak improves:

my @in_order = ($str =~ m{ ^(?> .*? ([abcd]) ) (?> .*? (?!\1) ([abcd]) ) (?> .*? (?!\1|\2) ([abcd]) ) (?> .*? (?!\1|\2|\3) ([abcd]) ) }x);
And, of course, YAW:
sub four_or_less { my ($s) = @_ ; $s =~ tr/abcd//cd ; my $c = '' ; $c .= $1 while ($s =~ m/([^ $c])/g) ; return $c ; }