Strange result with simple regex
I am working on regex right now and am experiencing strange behavior:
The following regex takes Q-123456-789
orQ-123456-789
params: '^\\q\\-\\d{6}\\-\\d{3}$|^\\Q\\-\\d{6}\\-\\d{3}$'
The following regex accepts R-123456-789
but does notR-123456-789
params: '^\\r\\-\\d{6}\\-\\d{3}$|^\\R\\-\\d{6}\\-\\d{3}$'
(I just replaced q
with r
and q
with r
)
source to share
Try [r]
for an exact match instead of \r
for the expected result
Try the following:
^[rR]-\d{6}\-\d{3}$
Use https://regex101.com/#javascript for testing
source to share