1. Common meta characters
| . |
Match any character other than line break |
| \w |
Match letters or numbers or underscores or kanji |
| \s |
Match any of the whitespace characters |
| \d |
Match numbers |
| \b |
Match the beginning or end of a word |
| ^ |
Match the start of a string |
| $ |
Match the end of a string |
2. Character escapes
Such as. , * must use \. and \*. To find \ itself, you also have to use \ \.
3. Repeat
| * |
Repeat 0 or more times |
| + |
Repeat one or more times |
| ? |
Repeat 0 or one time |
| N |
Repeat n times |
| {N,} |
Repeat N or more times |
| {N,m} |
Repeat N to M times |
[All-in-one] indicates that one
4. Branch Matching
The specific method is to separate the different rules with a |
0\d{2}-\d{8}|0\d{3}-\d{7} This expression can match two phone numbers separated by a hyphen: a three-bit area code, a 8-bit local number (such as 010-12345678), a 4-bit area code, and a 7-bit local number (0376-2233445).
5. Grouping is about to be () as a group
mentioned earlier how to repeat a single character (directly after the character with a qualifier); Repeat multiple characters with parentheses to specify the sub-expression (also called grouping), then you can specify the number of repetitions of the subexpression, and you can do some other actions on the subexpression (described later).
(\d{1,3}\.) {3}\d{1,3} is a simple IP-address matching expression. To understand this expression, parse it in the following order:\d{1,3} matches numbers from 1 to 3 digits,(\d{1,3}\.) {3} matches three digits plus an English period (this whole is the grouping) repeats 3 times, and finally adds one to three digits (\d{1,3}).
Http://tool.oschina.net/regex regular Match Test
Regular-expression Learning