Re: Matching at least $x words out of @words
Yitzchak Scott-Thoennes <[email protected]>
| Newsgroups | gmane.comp.lang.perl.fun |
|---|---|
| Organization | bs"d |
| Message-ID | <[email protected]> |
On Thu, May 05, 2005 at 09:41:46PM -0400, Rick Delaney wrote: > On Fri, May 06, 2005 at 02:05:02AM +0200, A. Pagaltzis wrote: > > * 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 > > / ($alt) .* (?!\1) ($alt) /x; Fails with words: (foo, foobar, foobaz) and string "foofoobar".