Given a list @words, verify that a string $target contains all words in any order, using one regular expression.

Constructs a regular expression using an "and" operation, using positive forward lookaheads.

ONCE: my $regex = join "", "^(?s)", map "(?=.*?\Q$_\E)", @words; $regex = qr/$regex/; ... AS_NEEDED: $found_all = $target =~ $regex;

Replies are listed 'Best First'.
Quantum::Superpositions did not overload =~
by princepawn (Parson) on Oct 20, 2000 at 18:36 UTC
    Drat. This won't work because he didn't:
    use Quantum::Superpositions; use strict; my @word; push @word, qr/\bfee\b/; push @word, qr/\bfi\b/; push @word, qr/\bfo\b/; push @word, qr/\bfum\b/; my $str = 'tweedle fee hi fi mo fo drunk on some fum'; if ($str =~ all(@word)) { warn "$str contains all of @word"; }
        Can this limitation be overcome in Perl 6? Is it too late to alert someone to this deficiency?