Match One of Many Alternatives
cat|dog|bird
matches one of cat
, dog
and bird
.
The order of the alternatives in the regex matters only when two of them can match at the same position in the string.
Alternatives are short-circuited(or eager). If the previous alternative matches, the rest won't continue to match at current position.
So Jane|Janet
can't match Janet
in Her name is Janet
, only Jane
is matched. To match word by word, use \bJane\b|\bJanet\b
instead.