I am trying to understand the following regex, I understand the initial part but I'm not able to figure out what {3,19} is doing here:
/[A-Z][A-Za-z0-9\s]{3,19}$/
The curly brackets are used to match exactly n instances of the proceeding character or pattern. For example, "/x{2}/" matches "xx".
Square brackets ( “[ ]” ): Any expression within square brackets [ ] is a character set; if any one of the characters matches the search string, the regex will pass the test return true.
To match a character having special meaning in regex, you need to use a escape sequence prefix with a backslash ( \ ). E.g., \. matches "." ; regex \+ matches "+" ; and regex \( matches "(" . You also need to use regex \\ to match "\" (back-slash).
Use Parentheses for Grouping and Capturing. By placing part of a regular expression inside round brackets or parentheses, you can group that part of the regular expression together. This allows you to apply a quantifier to the entire group or to restrict alternation to part of the regex.
That is the custom repetition operation known as the Quantifier.
\d{3}
will find exactly three digits.
[a-c]{1,3}
will find any occurrance of a, b, or c at least one time, but up to three times.
\w{0,1}
means a word character will be optionally found. This is the same as placing a Question Mark, e.g.: \w?
(\d\w){1,}
will find any combination of a Digit followed by a Word Character at least One time, but up to infinite times. So it would match 1k1k2k4k1k5j2j9k4h1k5k
This is the same as a Plus symbol, e.g.: (\d\w)+
b{0,}\d
will optionally find the letter b
followed by a digit, but could also match infinite letter b
's followed by a digit. So it will match 5
, b5
, or even bbbbbbb5
. This is the same as an Asterisk. e.g.: b*\d
Quantifiers
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With