|
Posted by Paul Lalli on June 18, 2008, 10:32 am
Please log in for more thread options > How can I build regex that matches all characters of the string $STR
> in any order with =A0.* added between any two characters: ?
> And without generating all N! transpositions (where N is length of
> $STR) ?
> Example.
> For $STR "abc", I want to match equivalent to:
> /(a.*b.*c)|(a.*c.*b)|(b.*a.*c)|(b.*c.*a)|(c.*a.*b)|(c.*b.*a)/
>
> Generating all transpositions is not feasible for larger legths of
> $STR.
> /[abc].*[abc].*[abc]/ is easy and fast but gives false positives.
> What is good solution ?
#!/usr/bin/perl
use strict;
use warnings;
use List::MoreUtils qw/all/;
$STR =3D "whatever";
if (all { $STR =3D~ /$_/ } qw/a b c/) {
print "Matched all of a, b, c\n";
}
__END__
Paul Lalli
|