0
Regex not working as expected !
Hi all, I wanted to create a regex for the pattern :- * 5 digits underscore 11 digits e.g. 12345_12345678901 My attempt :- /\d{5}[ _ ]\d{11}/ Failure case :- It is giving me true even if the length is increasing. E.g. 123456_12345678901,12345_1234567890123
8 Réponses
+ 3
Ashutosh Raturi
put \b at the start and at the end of your expression
+ 2
Ashutosh Raturi, as FF9900 said:
/^\d{5}[_]\d{11}$/
^ for start
$ for end
You should also remove spaces from square brackets
+ 1
FF9900 😎
online regex testers are super useful.
0
FF9900 can you please tell me how to do that?
0
Thanks to everyone for quick help 😃
0
Ashutosh Raturi
OrHy3 's
/^\d{5}_\d{11}$/
is more strict.
it will not match
#12345_12345678901
or
-12345_12345678901-
while
/\b\d{5}_\d{11}\b/
will match them
as FF9900 said, it depends on your use case.