I have searched around and cannot find an answer to my problem.
I have a range of numbers that I need to match against, it can be any one of these numbers but it must be a full match on a number not partially matched, see below:
Numbers to match against:
4 46 64
Now if I have the number 48, the regular expression should fail as the number 48 does not exist. My regex seems to matching on all of the number 4's for example and that is my issue.
Regular Expression:
/4|46|64/g
The text to match against is:
48
Result:
0-1: 4
See my example on an online regex tester:
https://regex101.com/r/QPUsqa/1
Thanks in advance.
Just add the anchors ^
and $
to modify it to:
^(?:4|46|64)$
Explanation:
^
- asserts the start of the string(?:4|46|64)
- matches either 4
or 46
or 64
$
- asserts the end of the string