We know \\ba\\b|\\bthe\\b
will match either word \"a\" or \"the\"
I want to build a regex expression to match a pattern li
As I understand you want some regex like this:
(?:a|the|one)\s+(?:reason|reasons)\s+(?:for|of)
It's so simple, just combine them by using groups.
see: DEMO
Note Your requirement above, its sound is not so strict for me, in case that you want to modify something by yourself, let's consider the explanation below
Explanation
(?:abc|ijk|xyz)
Any word abc
, ijk
or xyz
which grouped by non-capture group (?:...)
means this word will not capture to regex variable $1
, $2
, $3
, ...
.
\s+
This is word delimiter which here I set it as any spaces, +
stands for 1 or more.