Possible Duplicate:
Regular Expressions: Is there an AND operator?
I let my users enter a search term: "foo bar".
I would to convert the user query to a string that matches the words, but ignoring the order:
bla foo bla bar = match
^^^ ^^^
bla bar bla foo = match (order = reversed)
^^^ ^^^
bla bla bla foo = no match (only one word)
^^^
bar bla bla bla = no match (only one word)
^^^
Note: The example contains 2 words, but my users will go wild, and will enter more words.
If the order is not to be ignored, it is simple: replace a spaces by ".*" and I have a very good match.
But how can I let the regular expression ignore the order, and still match both (or more) words?
Do I need to generate a regex that will match possible combinations of order?