Le jeudi 05 mai 2005 � 15:24, Jos� Castro �crivait:
> Hi, folks.
>
> So suppose you want a regular expression to match at least one of
> three words:
>
> /word1|word2|word3/
>
> What solution would you use if you wanted at least _two_ of those
> three words?
my @words = qw( foo bar foobar );
$re = join '', map { '(?=.*(' . (quotemeta) . '))?' } @words;
$re = qr/$re/;
my @matches = grep defined, "foo bar baz" =~ $re;
The capturing parent allow you know which word was matched.
--
Philippe "BooK" Bruhat
He who revels in being bigger forgets that he is the larger target.
(Moral from Groo #5 (Image))