1. The most important three symbols in regular expressions:
1.1 B
In regular expressions, B has 3 types of parentheses:
1.1.1 square brackets "[".
The square brackets "[" are the characters that need to be matched. Bracketed content only matches one single character.
^[ab]$
1.1.2 Curly Brace "{"
The curly brace "{" is the number of matching characters specified.
^[ab]{3}$
1.1.3 Parenthesis "("
The parentheses "(" are used for grouping.)
^ (AB) $
1.2 C
The caret "^" indicates the beginning of the regular type.
^a
^ When used at the beginning of the brackets, the characters in parentheses are excluded.
^[^0-9]$
1.3 $
The dollar sign "$" indicates the end of the regular type.
com$
2. Regular expression validation
Recommend a validation regular expression URL: https://regexper.com/
2.1 Example
^[0-9]{3,7}$
The above regular expression is a number with a minimum length of 3 and a maximum of 7.
The result of the validation is:
2.2 ' │ ' symbol equals or operation
^ (1|2) $
3. Quick command
3.1 \d = number [0-9] Note D preceded by an escape character \
^\d$
Uppercase d:\d denotes non-numeric
^\d$
3.2 Underline any word character \w
^\w$
Capital W: \w denotes non-word
^\w$
3.3 0 times or more occurrences *
^[0-9]*$
3.4 At least once occurred +
^[0-9]+$
3.5 0 or 1 times?
^[0-9]?$
2017.8.25 Update
4. Non-greedy mode
Add a question mark directly behind the quantifier? It's a non-greedy pattern.
/(
JavaScript Regular expression popular explanation fast memory