Re: Matching at least $x words out of @words

2005-05-09 Thread Sven Neuhaus
On Thu, May 05, 2005 at 03:24:22PM +0100, José Castro wrote: 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? Isn't there a neater (and probably twisted, of

Re: Matching at least $x words out of @words

2005-05-09 Thread Paul Johnson
On Mon, May 09, 2005 at 10:27:48AM +0200, Sven Neuhaus wrote: On Thu, May 05, 2005 at 03:24:22PM +0100, José Castro wrote: This is fwp. I would use this perlish solution: @a = $x =~ /word1|word2|word3/g; $count = scalar @a; Without commenting on the solution, the fwp version of this (and

Re: Matching at least $x words out of @words

2005-05-09 Thread A. Pagaltzis
* A. Pagaltzis [EMAIL PROTECTED] [2005-05-09 12:10]: The problem with this and all the grep solutions is that you ^^ dont know whether you matched the same alternate multiple times, Err, that bit was non-sense, of course. I need some coffee.

Re: Matching at least $x words out of @words

2005-05-06 Thread Yitzchak Scott-Thoennes
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/

Re: Matching at least $x words out of @words

2005-05-06 Thread Philippe 'BooK' Bruhat
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: Matching at least $x words out of @words

2005-05-06 Thread Rick Delaney
On Fri, May 06, 2005 at 02:21:17AM -0700, Yitzchak Scott-Thoennes wrote: On Thu, May 05, 2005 at 09:41:46PM -0400, Rick Delaney wrote: / ($alt) .* (?!\1) ($alt) /x; Fails with words: (foo, foobar, foobaz) and string foofoobar. So it does. The overlapping strings also cause

Re: Matching at least $x words out of @words

2005-05-06 Thread Aaron Crane
Rick Delaney writes: The overlapping strings also cause problems for this method: $x = grep { $string =~ m/$_/ } @words; If $string is foobar and @words is qw(foo foobar) then this results in two words found which I don't think the OP was looking for. $x = grep { $string =~

RE: Matching at least $x words out of @words

2005-05-05 Thread Iain Loasby
-Original Message- From: José Castro [mailto:[EMAIL PROTECTED] Sent: 05 May 2005 15:24 [snip] Isn't there a neater (and probably twisted, of course) way of saying /match at least $x of the words in @words/ $x = grep { $string =~ m/$_/ } @words http://www.bbc.co.uk/ This

RE: Matching at least $x words out of @words

2005-05-05 Thread Allen, Greg
safer: $x = grep { $string =~ quotemeta } @words Greg -Original Message- From: Iain Loasby [mailto:[EMAIL PROTECTED] Sent: Thursday, May 05, 2005 3:39 PM To: José Castro; fwp@perl.org Subject: RE: Matching at least $x words out of @words -Original Message- From: José

Re: Matching at least $x words out of @words

2005-05-05 Thread A. Pagaltzis
* 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)