| Symbol |
Description |
Example |
| Literal |
Match the value of a string |
Foo |
| Re1|re2 |
Match regular expression Re1 or Re2 |
Foo|bar |
| . |
Match any character (except line breaks) |
B.b |
| ^ |
Match the start of a string |
^dear |
| $ |
Match the end of a string |
/bin/*sh$ |
| * |
Matches the preceding occurrence of the regular expression 0 or more times |
[a-za-z0-9]* |
| + |
Matches the preceding occurrence of the regular expression 1 or more times |
[a-z]+\.com |
| ? |
Matches the preceding occurrence of the regular expression 0 or more times |
Goo? |
| N |
Matches the preceding occurrence of the regular expression n times |
[0-9] {3} |
| {M,n} |
Matches regular expressions that recur m-n times |
[0-9] {5,9} |
| [...] |
Match any one of the characters that appear in the character set |
[Aeiou] |
| [.. X-y:] |
Match any character from character X to Y |
[0-9],[a-za-z] |
| [^...] |
does not match any one of the characters that appear in this character set, Include a range of characters |
[^a-za-z0-9_] |
| (*|+|?| {}) |
For any "non-greedy" version that appears above Repeat match number symbol (*,+,?,{}) |
.*? [A-z] |
| (...) |
Match enclosing parentheses in a regular expression (RE), and keep it as a child group |
([0-9]{3})?, f (oo|u) bar |
|
|
|
|
|
|
| Special symbols |
|
|
| \d |
Match any number, and [0-9] (\d is the inverse of \d: any non-number symbol) |
Data\d+.txt |
| \w |
Match any numeric alphabetic character (\w is the \w) |
[a-za-z_]\w+ |
| \s |
Matches any whitespace character, and [\n\t\r\v\f] (\s is the \s) |
Of\sthe |
| \b |
Match word boundaries (\b is the \b) |
\bthe\b |
| \nn |
Match a saved child group |
Price: \16 |
| \c |
Match the special character C individually |
\.,\\,\* |
| \a (\z) |
Start of Match string (end) |
\adear |
|
|
|
|
|
|
|
|
|
| Common regular expression functions and methods |
|
|
| Compile (pattern,flags=0) |
Compiles the regular expression pattern and returns a Regex object |
|
| Match (Pattern,string,flags=0) |
Match the string with the regular expression pattern, Match successfully returns the Match object, otherwise none is returned |
|
| Search (pattern,string,flags=0) |
Matches the first occurrence of a string with a regular expression pattern, Match successfully returns the Match object, otherwise none is returned |
|
| FindAll (Pattern,string[,flags]) |
Finds all (non-repeating) occurrences of the regular expression pattern in string strings, Returns a list of matching objects |
|
| Finditer (Pattern,string[,flags]) |
Searches for a string, returning an iterator that sequentially accesses each match result (Match object) |
|
| Split (pattern,string,max=0) |
Returns a list after the string is split in pattern mode. Max is used to specify the maximum number of splits and does not specify that all will be split. |
|
| Sub (pattern,rep1,string,max=0) |
Returns the replaced string after using REPL to replace each substring of a string that matches the pattern. |
|
| Group (num=0) |
Return all matching objects |
|
| Groups () |
Returns a tuple that contains all of the matched child tuples |
|