From: Joel VanderWerf Date: 2006-02-04T07:03:21+09:00 Subject: Re: Regexp question for doing "and" searches Jeff Cohen wrote: > Just can't quite figure this one out. > > Given a search phrase like "one two three", I want to search a list of > text strings for onex that contain ALL of those words, but not > necessarily in that order. > > The hard part for me is the "not necessarily in that order". > > Using '\b(one|two|three)\b' will match if at least one of them occurs in > any order, but I need all of them to match *and* be in any order. > > two one three => match > one three => does not match Seems to work: s = "foo two bar three zap one" rx = /^(?=.*one)(?=.*two).*three/m p (rx =~ s) s = "one three" p (rx =~ s) Works like this too: rx = /^(?=.*one)(?=.*two)(?=.*three)/m -- vjoel : Joel VanderWerf : path berkeley edu : 510 665 3407