Regular Expressions 101

Community Patterns

Community Library Entry

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 - 2 years ago (Last modified 2 years ago)