Regular Expression learning and collation
/: It is a delimiters. The characters to be matched are generally placed in the delimiters;
2. Common metacharacters
1) +: appears once or multiple times
2) *: zero or multiple occurrences
3 )? : Zero or one occurrence
3. Qualifier
1) character 1 character 2 {n} indicates the matching result of character 2 appearing n times in a row
Character 1 character 2 {n,} indicates the matching result of character 2 that appears n times or more times consecutively
(Character 1 character 2) {n} indicates the matching result of Character 1 character 2 appearing n times in a row
(Character 1 character 2) {n,} indicates the matching result of Character 1 character 2 appearing n times or more times consecutively
Character 1 character 2 {n, m} indicates the matching result between n and m consecutive occurrences of character 2
Example:Text to be matched abcabccabbcabccc
Abc {1} indicates that abcabccabbcabccc occurs once in c.
Abc {2} indicates that c appears twice abcabccabbcabccc
Abc {1,} indicates that c appears once or more abcabccabbcabccc
(Abc) {1,} indicates that abc appears once or more abcabccabbcabccc
4. Special and important metacharacters
. Used to match any character except line breaks
\ S is used to match spaces (lower case)
\ S is used to match content other than spaces (uppercase)
\ D is used to match numbers
\ D is used to match non-Numbers
\ W is used to match letters, numbers, or underscores
\ W is used to match all characters that do not match \ w.
5. Positioning Operator
1) ^: starting with the target string
1) $: End of the target string
Example:
The name must start with an 11-digit number: /^ 1 [3 | 4 | 5 | 8] [0-9] \ d {8} $ // 13, 14, 15, 18, the last eight digits are allowed between 0-9.
Determination of numbers within the range of 1000-9999: ^ ([1-9] \ d {3}) $
Number judgment within the range of 2000-2077: ^ 20 ([0-6] \ d | 7 [0-7]) $ // You must note that there are ten digits: 77 can be split into two parts: 0-9 for a single digit in the case of 10-6; 0-7 for a single digit in the case of 10-7.
^ Indicates that the row input starts matching;
$ Indicates the end MATCH mode of the input. The number indicates the original meaning, and the number indicates the number of digits;
\ D represents a digit in 0-9;
| Yes or indicates the selection condition;
() Is a group. If the regular expression is not a group, it is necessary to separate the regular expression into several small regular expressions.