/^(?=.*a)(?=.*b)(?=.*c).*d/ or die;
If you want to know the order in which they came,
my %order; @order{qw( a b c d )} = map length, /^(?=(.*?)a)(?=(.*?)b)(?=(.*?)c)(.*?)d/ or die; my @ordered = sort { $order{$a} <=> $order{$b} } keys %order;
This is probably slow for long strings.
Update: Actually, no need for a hash.
my @order = map length, /^(?=(.*?)a)(?=(.*?)b)(?=(.*?)c)(.*?)d/ or die; my @ordered = ( qw( a b c d ) )[ sort { $order[$a] <=> $order[$b] } 0..$#order ];
Update: Back to the practical, using multiple regexp and saving @- should be much faster. Especially if scanning for constants.
my @unordered = qw( a b c d ); my @order; for my $s (@unordered) { push @order, /\Q$s/ ? $-[0] : die; } my @ordered = @unordered[ sort { $order[$a] <=> $order[$b] } 0..$#order ];
In reply to Re: How to replace greedy alternation?
by ikegami
in thread How to replace greedy alternation?
by adamcrussell
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |