Home > front end >  Questions about the regular expression in Java Script
Questions about the regular expression in Java Script

Time:02-11

In the regular expression of JS encountered this problem, I understand before \ d {3}, and a digital said, the 1000 has four Numbers in the following example, won't meet \ d {3}, is that it should return false, but why alert (the) (aa) pattern return is true, and I found how to change to 1000, it is always true, 0000 is also behind the same is true, what is the middle of the 01 add or reduce digital displays false, all is to consult, as I understand where there is the problem, thank you

Var aa='1000-01-0000;
Var pattern=/\ d {3} - {2} - \ d \ d {4}/;
Alert (pattern. The test (aa));

CodePudding user response:

Seem to know the reason, to add ^ and $to var pattern=/^ \ d {3} - {2} - \ d \ d {4} $/like is no problem, also want to consult with me see this style, have a plenty of \ d {2, 3} want to consult this style said what does that mean

CodePudding user response:

\ d {2, 3}//the number do 2, up to three Numbers, that is, matching two or three figures
\ d {3}//is only matching three Numbers
  • Related