var rxDatePattern = new RegExp("^(?:\\d*\\.\\d{" + no + "})$");
This is the regular exp pattern im using to accept numeric values with 3 digits after decimal.The value is stored in the variable no….
This is working fine , but i kind of did not understand the pattern , can anybody help me the pattern..
Thanks
^and$are anchors for the start and end of string, respectively. They make the regex match a complete string in this case instead of just a substring.\dstands for a single digit, while\d*is, due to the*quantifier, a series of at least zero digits. Then follows a literal dot, matching, well, a dot (.) and a variable number of digits again, e.g.\d{3}.The reason why the regex contains
\\dinstead of\dis that\is also the escape character for strings in JavaScript. So to include a literal backslash in a regex that is contained in a string you have to escape the backslash once, so the regex engine sees an actual backslash.Finally all this is enclosed in a non-capturing group
(?:...), although I don’t quite see why. It has no effect in this case and could be left out as well.So for
no= 2 this would match strings likebut not strings like