http://qs321.pair.com?node_id=125027

fsn has asked for the wisdom of the Perl Monks concerning the following question:

Hello Monks. I am a humble seeker of your wisdom.

I need help writing a RegExp that matches when two words both are present in a string, but the order is unknown. Also, the words might or might not be next to eachother. The regexp should NOT match when only one word is present.

With nested if's it is trivial, but I would like to do it with a single regexp.

Example: If I have a file:

foo bar bar foo foo bar baz barbazfoo foofoobar

I wan't to match lines 1,2,6 and 7, but not 3 thorugh 5, using some match for foo and bar.

Any idea?

Edit Masem 2001-11-13 - Changed title from 'Regular expression and'