* Josà Castro <[EMAIL PROTECTED]> [2005-05-05 16:30]:
> 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?
$alt = join '|', qw( word1 word2 word3 );
/ ($alt) .* ($alt) (?(?{ $1 eq $2 })(?!)) /x
Note:
It can probably be reduced further to remove the need for $alt
duplication in the regex. The only way I can see would entail
using (?{}) and local to save matches, though.
Warning:
Lots of backtracking. Use a grep solution as shown by others in
pratice.
Regards,
--
#Aristotle
*AUTOLOAD=*_=sub{s/(.*)::(.*)/print$2,(",$\/"," ")[defined wantarray]/e;$1};
&Just->another->Perl->hacker;