Is there any way to abbreviate this?
/ 1111 | 2222 /
I mean, I want a regex that matches 1111 or 2222 when they have white spaces at the beginning and at the end.
I have tried this below but it is not working:
/ 1111|2222 /
Is there any way to abbreviate this?
/ 1111 | 2222 /
I mean, I want a regex that matches 1111 or 2222 when they have white spaces at the beginning and at the end.
I have tried this below but it is not working:
/ 1111|2222 /
The / 1111|2222 /
pattern matches 1111
or 2222
.
You want to use a grouping construct here:
/ (?:1111|2222) /
The (?:1111|2222)
is a non-capturing group that allows matching alternative char/pattern sequences.
Or, with a capturing group (good for regex engines that do not support non-capturing groups, e.g. POSIX ERE, XML Schema regex engines):
/ (1111|2222) /