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?


Isn't there a neater (and probably twisted, of course) way of saying
/match at least $x of the words in @words/ without having to do
something like:

1) get all the combinations of $x words in @words
2) for each of those, find the permutations ( [qw/word1, word2/],
  [qw/word2, word1/] )
3) create the regexen ( /word1.*word2/, /word2.*word1/ )
4) join them all with "|" and create the regex out of it

Something in the lines of:

join "|", map { join ".*", @$_ } map { [permutations(@$_)] } combinations($x, 
@words)

(code untested, of course)

There's gotta be a better way, no? Any comments?

Cheers,

jac

--
Jose Alves de Castro <[EMAIL PROTECTED]>
      http://jose-castro.org/

Reply via email to