In fact, regular is not difficult, is not a long time to see.
Common regular specification | ||
No. | specification | description |
1 | \\ | Specify a backslash '\' character |
2 | \t | For a tab |
3 | \n | Newline |
4 | [abc] | Abc character |
5 | [^abc] | Any character except abc's |
6 | [A-zA-Z0-9] | It is represented by a character numbers |
7 | \d | Represent numbers |
8 | \D | It represents a non-digital |
9 | \w | Table alphanumeric characters and underscores |
10 | \W | It represents a non-alphanumeric characters and underscores |
11 | \s | Represent all whitespace |
12 | \S | It represents all non-whitespace characters |
13 | ^ | Beginning of the line |
14 | $ | End of the line |
15 | . | Matches any character except a newline |
A logical operation (XY represents a series of specifications) | ||
No. | specification | description |
1 | XY | X Y followed later Specification |
2 | X | Y | Specification Specification X or Y |
3 | (X ) | Capture a set of specifications as |
Calculating the number (X represents a set of specifications) | ||
No. | specification | description |
1 | X | Must appear once |
2 | X? | Can appear 0 or 1 times |
3 | X* | 0,1 or may occur many times |
4 | X+ | It may appear once or multiple times |
5 | X{n} | Must appear n times |
6 | X{N,} | Must appear n times or more |
7 | X{n,m } | It must appear nm times |
Regular expression:
var reg = /^1[3|4|5|7|8][0-9]{9}$/;
On a regular split.
^1 | Beginning with 1 |
[3|4|5|7|8] | The second digit can be 3,4,5,7,8 |
[0-9]{9} | A total of 11 phone numbers, and the remaining 9 digits must appear 9 times |
$ | End of the line |