1. regular expression syntax is composed of characters and operators
. | It represents any single character | |
[] | Characters, a single character is given in the range of | [Abc] represents a, b, c, [a - z] z represents a single character to the |
[^] | Non characters, a single character is given to the negative range | [^ Abc] represents a or b or c non-single character |
* | Previous character 0 times or an unlimited number of extensions | abc * represents ab, abc, abcc, abccc etc. |
+ | 1 previous character or unlimited expansion | It represents abc + abc, abcc, abccc etc. |
? | Previous character 0 or 1 extension | abc? Represents ab, abc |
| | Any expression about a | abc | def represents abc, def |
{m} | M times before the extended character | ab {2} c represents abbc |
{m,n} | A front extended to n times m times characters (including n times) | represents ab {1,2} c abc, abbc |
^ | Matches the beginning of string | ^ Abc abc and to indicate the beginning of a string |
$ | End of the string | $ Abc and abc indicate the end of a string |
() | Packet marking, internal use only | operator | (Abc) represents abc, (abc | def) represents abc, def |
\d | Number, is equivalent to [0 - 9] | |
\w | A single character, equivalent to [A-Za-z0-9_] |
2. Call mode: import re
raw string type (native string type) is a string without escape character again escaped
3. Re library function main functions:
4. r.search (pattern, string, flags = 0) flags: Flag normal control:
5. Match object properties:
6. The method Match object:
7. Re default library greedy match, i.e., the output of the longest string
The minimum match operator: output may be different as long as the length, can be increased by the operator? Becomes the minimum match