|
85 | 85 | \\ Matches a literal backslash. |
86 | 86 |
|
87 | 87 | This module exports the following functions: |
88 | | - match Match a regular expression pattern to the beginning of a string. |
89 | | - search Search a string for the presence of a pattern. |
90 | | - sub Substitute occurrences of a pattern found in a string. |
91 | | - subn Same as sub, but also return the number of substitutions made. |
92 | | - split Split a string by the occurrences of a pattern. |
93 | | - findall Find all occurrences of a pattern in a string. |
94 | | - finditer Return an iterator yielding a match object for each match. |
95 | | - compile Compile a pattern into a RegexObject. |
96 | | - purge Clear the regular expression cache. |
97 | | - escape Backslash all non-alphanumerics in a string. |
| 88 | + match Match a regular expression pattern to the beginning of a string. |
| 89 | + fullmatch Match a regular expression pattern to all of a string. |
| 90 | + search Search a string for the presence of a pattern. |
| 91 | + sub Substitute occurrences of a pattern found in a string. |
| 92 | + subn Same as sub, but also return the number of substitutions made. |
| 93 | + split Split a string by the occurrences of a pattern. |
| 94 | + findall Find all occurrences of a pattern in a string. |
| 95 | + finditer Return an iterator yielding a match object for each match. |
| 96 | + compile Compile a pattern into a RegexObject. |
| 97 | + purge Clear the regular expression cache. |
| 98 | + escape Backslash all non-alphanumerics in a string. |
98 | 99 |
|
99 | 100 | Some of the functions in this module takes flags as optional parameters: |
100 | 101 | A ASCII For string patterns, make \w, \W, \b, \B, \d, \D |
|
123 | 124 | import sre_parse |
124 | 125 |
|
125 | 126 | # public symbols |
126 | | -__all__ = [ "match", "search", "sub", "subn", "split", "findall", |
| 127 | +__all__ = [ "match", "fullmatch", "search", "sub", "subn", "split", "findall", |
127 | 128 | "compile", "purge", "template", "escape", "A", "I", "L", "M", "S", "X", |
128 | 129 | "U", "ASCII", "IGNORECASE", "LOCALE", "MULTILINE", "DOTALL", "VERBOSE", |
129 | 130 | "UNICODE", "error" ] |
@@ -154,6 +155,11 @@ def match(pattern, string, flags=0): |
154 | 155 | a match object, or None if no match was found.""" |
155 | 156 | return _compile(pattern, flags).match(string) |
156 | 157 |
|
| 158 | +def fullmatch(pattern, string, flags=0): |
| 159 | + """Try to apply the pattern to all of the string, returning |
| 160 | + a match object, or None if no match was found.""" |
| 161 | + return _compile(pattern, flags).fullmatch(string) |
| 162 | + |
157 | 163 | def search(pattern, string, flags=0): |
158 | 164 | """Scan through string looking for a match to the pattern, returning |
159 | 165 | a match object, or None if no match was found.""" |
|
0 commit comments