Regular Expressions 101

Community Patterns

Match all of the words in arbitrary order

0

Regular Expression
PCRE2 (PHP >=7.3)

/
^(?=.*min(?:imum)?)(?=.*speed|.*velocity)(?=.*edge).*$
/
gmi

Description

Specify words that all have to be contained in a line; the order is arbitrary and there may be other words around them. This is most useful for searching identifiers in source code as normal word boundaries (space or punctuation) cannot be used in these cases.

The example regular expression matches any line that contains minimum (or min), speed (or velocity) and edge in any order. Append a ? to a lookahead group to make that respective word optional.

Submitted by Sebastian Zander - a year ago (Last modified a year ago)