Regex – Regular Expressions: Is there an AND operator

lookaheadregex

Obviously, you can use the | (pipe?) to represent OR, but is there a way to represent AND as well?

Specifically, I'd like to match paragraphs of text that contain ALL of a certain phrase, but in no particular order.

Best Answer

Use a non-consuming regular expression.

The typical (i.e. Perl/Java) notation is:

(?=expr)

This means "match expr but after that continue matching at the original match-point."

You can do as many of these as you want, and this will be an "and." Example:

(?=match this expression)(?=match this too)(?=oh, and this)

You can even add capture groups inside the non-consuming expressions if you need to save some of the data therein.