First, Python's regular
1.python Regular expressions using the re-module
Import Re # matching using the match method result = Re.match (regular expression, string to match)# If the previous step matches the data, you can use the group method to extract the data Result.group ()
Second, the regular rule
1. String
| character |
function |
| . |
Matches any of 1 characters (except \ n) |
| [ ] |
Match the characters enumerated in [] |
| \d |
Match number, which is 0-9 |
| \d |
Matches a non-numeric, that is, not a number |
| \s |
Match whitespace, that is, the Space, TAB key |
| \s |
Match non-whitespace |
| \w |
Match word characters, i.e. A-Z, A-Z, 0-9, _ |
| \w |
Match non-word characters |
2. Indicate quantity
| character |
function |
| * |
Matches the previous character 0 or more times, which is optional |
| + |
Match the previous character 1 or more times, i.e. at least 1 times |
| ? |
Matches the previous character 1 or 0 times, either 1 times or no |
| {m} |
Match the previous character appears m times |
| {m,} |
Matches the previous character at least m times |
| {M,n} |
Match the previous character appears from M to N times |
python--Regular Expressions