1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245
|
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html><head><title>Python: module re</title>
<meta charset="utf-8">
</head><body bgcolor="#f0f0f8">
<table width="100%" cellspacing=0 cellpadding=2 border=0 summary="heading">
<tr bgcolor="#7799ee">
<td valign=bottom> <br>
<font color="#ffffff" face="helvetica, arial"> <br><big><big><strong>re</strong></big></big> (version 2.2.1)</font></td
><td align=right valign=bottom
><font color="#ffffff" face="helvetica, arial"><a href=".">index</a><br><a href="file:/usr/local/Cellar/python/2.7.10_2/Frameworks/Python.framework/Versions/2.7/lib/python2.7/re.py">/usr/local/Cellar/python/2.7.10_2/Frameworks/Python.framework/Versions/2.7/lib/python2.7/re.py</a><br><a href="http://docs.python.org/library/re">Module Docs</a></font></td></tr></table>
<p><tt>Support for regular expressions (RE).<br>
<br>
This module provides regular expression matching operations similar to<br>
those found in Perl. It supports both 8-bit and Unicode strings; both<br>
the pattern and the strings being processed can contain null bytes and<br>
characters outside the US ASCII range.<br>
<br>
Regular expressions can contain both special and ordinary characters.<br>
Most ordinary characters, like "A", "a", or "0", are the simplest<br>
regular expressions; they simply match themselves. You can<br>
concatenate ordinary characters, so last matches the string 'last'.<br>
<br>
The special characters are:<br>
"." Matches any character except a newline.<br>
"^" Matches the start of the string.<br>
"$" Matches the end of the string or just before the newline at<br>
the end of the string.<br>
"*" Matches 0 or more (greedy) repetitions of the preceding RE.<br>
Greedy means that it will match as many repetitions as possible.<br>
"+" Matches 1 or more (greedy) repetitions of the preceding RE.<br>
"?" Matches 0 or 1 (greedy) of the preceding RE.<br>
*?,+?,?? Non-greedy versions of the previous three special characters.<br>
{m,n} Matches from m to n repetitions of the preceding RE.<br>
{m,n}? Non-greedy version of the above.<br>
"\\" Either escapes special characters or signals a special sequence.<br>
[] Indicates a set of characters.<br>
A "^" as the first character indicates a complementing set.<br>
"|" A|B, creates an RE that will match either A or B.<br>
(...) Matches the RE inside the parentheses.<br>
The contents can be retrieved or matched later in the string.<br>
(?iLmsux) Set the I, L, M, S, U, or X flag for the RE (see below).<br>
(?:...) Non-grouping version of regular parentheses.<br>
(?P<name>...) The substring matched by the group is accessible by name.<br>
(?P=name) Matches the text matched earlier by the group named name.<br>
(?#...) A comment; ignored.<br>
(?=...) Matches if ... matches next, but doesn't consume the string.<br>
(?!...) Matches if ... doesn't match next.<br>
(?<=...) Matches if preceded by ... (must be fixed length).<br>
(?<!...) Matches if not preceded by ... (must be fixed length).<br>
(?(id/name)yes|no) Matches yes pattern if the group with id/name matched,<br>
the (optional) no pattern otherwise.<br>
<br>
The special sequences consist of "\\" and a character from the list<br>
below. If the ordinary character is not on the list, then the<br>
resulting RE will match the second character.<br>
\number Matches the contents of the group of the same number.<br>
\A Matches only at the start of the string.<br>
\Z Matches only at the end of the string.<br>
\b Matches the empty string, but only at the start or end of a word.<br>
\B Matches the empty string, but not at the start or end of a word.<br>
\d Matches any decimal digit; equivalent to the set [0-9].<br>
\D Matches any non-digit character; equivalent to the set [^0-9].<br>
\s Matches any whitespace character; equivalent to [ \t\n\r\f\v].<br>
\S Matches any non-whitespace character; equiv. to [^ \t\n\r\f\v].<br>
\w Matches any alphanumeric character; equivalent to [a-zA-Z0-9_].<br>
With LOCALE, it will match the set [0-9_] plus characters defined<br>
as letters for the current locale.<br>
\W Matches the complement of \w.<br>
\\ Matches a literal backslash.<br>
<br>
This module exports the following functions:<br>
match Match a regular expression pattern to the beginning of a string.<br>
search Search a string for the presence of a pattern.<br>
sub Substitute occurrences of a pattern found in a string.<br>
subn Same as sub, but also return the number of substitutions made.<br>
split Split a string by the occurrences of a pattern.<br>
findall Find all occurrences of a pattern in a string.<br>
finditer Return an iterator yielding a match object for each match.<br>
compile Compile a pattern into a RegexObject.<br>
purge Clear the regular expression cache.<br>
escape Backslash all non-alphanumerics in a string.<br>
<br>
Some of the functions in this module takes flags as optional parameters:<br>
I IGNORECASE Perform case-insensitive matching.<br>
L LOCALE Make \w, \W, \b, \B, dependent on the current locale.<br>
M MULTILINE "^" matches the beginning of lines (after a newline)<br>
as well as the string.<br>
"$" matches the end of lines (before a newline) as well<br>
as the end of the string.<br>
S DOTALL "." matches any character at all, including the newline.<br>
X VERBOSE Ignore whitespace and comments for nicer looking RE's.<br>
U UNICODE Make \w, \W, \b, \B, dependent on the Unicode locale.<br>
<br>
This module also defines an exception '<a href="#error">error</a>'.</tt></p>
<p>
<table width="100%" cellspacing=0 cellpadding=2 border=0 summary="section">
<tr bgcolor="#aa55cc">
<td colspan=3 valign=bottom> <br>
<font color="#ffffff" face="helvetica, arial"><big><strong>Modules</strong></big></font></td></tr>
<tr><td bgcolor="#aa55cc"><tt> </tt></td><td> </td>
<td width="100%"><table width="100%" summary="list"><tr><td width="25%" valign=top><a href="_locale.html">_locale</a><br>
<a href="copy_reg.html">copy_reg</a><br>
</td><td width="25%" valign=top><a href="sre_compile.html">sre_compile</a><br>
<a href="sre_parse.html">sre_parse</a><br>
</td><td width="25%" valign=top><a href="sys.html">sys</a><br>
</td><td width="25%" valign=top></td></tr></table></td></tr></table><p>
<table width="100%" cellspacing=0 cellpadding=2 border=0 summary="section">
<tr bgcolor="#ee77aa">
<td colspan=3 valign=bottom> <br>
<font color="#ffffff" face="helvetica, arial"><big><strong>Classes</strong></big></font></td></tr>
<tr><td bgcolor="#ee77aa"><tt> </tt></td><td> </td>
<td width="100%"><dl>
<dt><font face="helvetica, arial"><a href="exceptions.html#Exception">exceptions.Exception</a>(<a href="exceptions.html#BaseException">exceptions.BaseException</a>)
</font></dt><dd>
<dl>
<dt><font face="helvetica, arial"><a href="sre_constants.html#error">sre_constants.error</a>
</font></dt></dl>
</dd>
</dl>
<p>
<table width="100%" cellspacing=0 cellpadding=2 border=0 summary="section">
<tr bgcolor="#ffc8d8">
<td colspan=3 valign=bottom> <br>
<font color="#000000" face="helvetica, arial"><a name="error">class <strong>error</strong></a>(<a href="exceptions.html#Exception">exceptions.Exception</a>)</font></td></tr>
<tr><td bgcolor="#ffc8d8"><tt> </tt></td><td> </td>
<td width="100%"><dl><dt>Method resolution order:</dt>
<dd><a href="sre_constants.html#error">error</a></dd>
<dd><a href="exceptions.html#Exception">exceptions.Exception</a></dd>
<dd><a href="exceptions.html#BaseException">exceptions.BaseException</a></dd>
<dd><a href="__builtin__.html#object">__builtin__.object</a></dd>
</dl>
<hr>
Data descriptors defined here:<br>
<dl><dt><strong>__weakref__</strong></dt>
<dd><tt>list of weak references to the object (if defined)</tt></dd>
</dl>
<hr>
Methods inherited from <a href="exceptions.html#Exception">exceptions.Exception</a>:<br>
<dl><dt><a name="error-__init__"><strong>__init__</strong></a>(...)</dt><dd><tt>x.<a href="#error-__init__">__init__</a>(...) initializes x; see help(type(x)) for signature</tt></dd></dl>
<hr>
Data and other attributes inherited from <a href="exceptions.html#Exception">exceptions.Exception</a>:<br>
<dl><dt><strong>__new__</strong> = <built-in method __new__ of type object><dd><tt>T.<a href="#error-__new__">__new__</a>(S, ...) -> a new object with type S, a subtype of T</tt></dl>
<hr>
Methods inherited from <a href="exceptions.html#BaseException">exceptions.BaseException</a>:<br>
<dl><dt><a name="error-__delattr__"><strong>__delattr__</strong></a>(...)</dt><dd><tt>x.<a href="#error-__delattr__">__delattr__</a>('name') <==> del x.name</tt></dd></dl>
<dl><dt><a name="error-__getattribute__"><strong>__getattribute__</strong></a>(...)</dt><dd><tt>x.<a href="#error-__getattribute__">__getattribute__</a>('name') <==> x.name</tt></dd></dl>
<dl><dt><a name="error-__getitem__"><strong>__getitem__</strong></a>(...)</dt><dd><tt>x.<a href="#error-__getitem__">__getitem__</a>(y) <==> x[y]</tt></dd></dl>
<dl><dt><a name="error-__getslice__"><strong>__getslice__</strong></a>(...)</dt><dd><tt>x.<a href="#error-__getslice__">__getslice__</a>(i, j) <==> x[i:j]<br>
<br>
Use of negative indices is not supported.</tt></dd></dl>
<dl><dt><a name="error-__reduce__"><strong>__reduce__</strong></a>(...)</dt></dl>
<dl><dt><a name="error-__repr__"><strong>__repr__</strong></a>(...)</dt><dd><tt>x.<a href="#error-__repr__">__repr__</a>() <==> repr(x)</tt></dd></dl>
<dl><dt><a name="error-__setattr__"><strong>__setattr__</strong></a>(...)</dt><dd><tt>x.<a href="#error-__setattr__">__setattr__</a>('name', value) <==> x.name = value</tt></dd></dl>
<dl><dt><a name="error-__setstate__"><strong>__setstate__</strong></a>(...)</dt></dl>
<dl><dt><a name="error-__str__"><strong>__str__</strong></a>(...)</dt><dd><tt>x.<a href="#error-__str__">__str__</a>() <==> str(x)</tt></dd></dl>
<dl><dt><a name="error-__unicode__"><strong>__unicode__</strong></a>(...)</dt></dl>
<hr>
Data descriptors inherited from <a href="exceptions.html#BaseException">exceptions.BaseException</a>:<br>
<dl><dt><strong>__dict__</strong></dt>
</dl>
<dl><dt><strong>args</strong></dt>
</dl>
<dl><dt><strong>message</strong></dt>
</dl>
</td></tr></table></td></tr></table><p>
<table width="100%" cellspacing=0 cellpadding=2 border=0 summary="section">
<tr bgcolor="#eeaa77">
<td colspan=3 valign=bottom> <br>
<font color="#ffffff" face="helvetica, arial"><big><strong>Functions</strong></big></font></td></tr>
<tr><td bgcolor="#eeaa77"><tt> </tt></td><td> </td>
<td width="100%"><dl><dt><a name="-compile"><strong>compile</strong></a>(pattern, flags<font color="#909090">=0</font>)</dt><dd><tt>Compile a regular expression pattern, returning a pattern object.</tt></dd></dl>
<dl><dt><a name="-escape"><strong>escape</strong></a>(pattern)</dt><dd><tt>Escape all non-alphanumeric characters in pattern.</tt></dd></dl>
<dl><dt><a name="-findall"><strong>findall</strong></a>(pattern, string, flags<font color="#909090">=0</font>)</dt><dd><tt>Return a list of all non-overlapping matches in the string.<br>
<br>
If one or more groups are present in the pattern, return a<br>
list of groups; this will be a list of tuples if the pattern<br>
has more than one group.<br>
<br>
Empty matches are included in the result.</tt></dd></dl>
<dl><dt><a name="-finditer"><strong>finditer</strong></a>(pattern, string, flags<font color="#909090">=0</font>)</dt><dd><tt>Return an iterator over all non-overlapping matches in the<br>
string. For each match, the iterator returns a match object.<br>
<br>
Empty matches are included in the result.</tt></dd></dl>
<dl><dt><a name="-match"><strong>match</strong></a>(pattern, string, flags<font color="#909090">=0</font>)</dt><dd><tt>Try to apply the pattern at the start of the string, returning<br>
a match object, or None if no match was found.</tt></dd></dl>
<dl><dt><a name="-purge"><strong>purge</strong></a>()</dt><dd><tt>Clear the regular expression cache</tt></dd></dl>
<dl><dt><a name="-search"><strong>search</strong></a>(pattern, string, flags<font color="#909090">=0</font>)</dt><dd><tt>Scan through string looking for a match to the pattern, returning<br>
a match object, or None if no match was found.</tt></dd></dl>
<dl><dt><a name="-split"><strong>split</strong></a>(pattern, string, maxsplit<font color="#909090">=0</font>, flags<font color="#909090">=0</font>)</dt><dd><tt>Split the source string by the occurrences of the pattern,<br>
returning a list containing the resulting substrings.</tt></dd></dl>
<dl><dt><a name="-sub"><strong>sub</strong></a>(pattern, repl, string, count<font color="#909090">=0</font>, flags<font color="#909090">=0</font>)</dt><dd><tt>Return the string obtained by replacing the leftmost<br>
non-overlapping occurrences of the pattern in string by the<br>
replacement repl. repl can be either a string or a callable;<br>
if a string, backslash escapes in it are processed. If it is<br>
a callable, it's passed the match object and must return<br>
a replacement string to be used.</tt></dd></dl>
<dl><dt><a name="-subn"><strong>subn</strong></a>(pattern, repl, string, count<font color="#909090">=0</font>, flags<font color="#909090">=0</font>)</dt><dd><tt>Return a 2-tuple containing (new_string, number).<br>
new_string is the string obtained by replacing the leftmost<br>
non-overlapping occurrences of the pattern in the source<br>
string by the replacement repl. number is the number of<br>
substitutions that were made. repl can be either a string or a<br>
callable; if a string, backslash escapes in it are processed.<br>
If it is a callable, it's passed the match object and must<br>
return a replacement string to be used.</tt></dd></dl>
<dl><dt><a name="-template"><strong>template</strong></a>(pattern, flags<font color="#909090">=0</font>)</dt><dd><tt>Compile a template pattern, returning a pattern object</tt></dd></dl>
</td></tr></table><p>
<table width="100%" cellspacing=0 cellpadding=2 border=0 summary="section">
<tr bgcolor="#55aa55">
<td colspan=3 valign=bottom> <br>
<font color="#ffffff" face="helvetica, arial"><big><strong>Data</strong></big></font></td></tr>
<tr><td bgcolor="#55aa55"><tt> </tt></td><td> </td>
<td width="100%"><strong>DOTALL</strong> = 16<br>
<strong>I</strong> = 2<br>
<strong>IGNORECASE</strong> = 2<br>
<strong>L</strong> = 4<br>
<strong>LOCALE</strong> = 4<br>
<strong>M</strong> = 8<br>
<strong>MULTILINE</strong> = 8<br>
<strong>S</strong> = 16<br>
<strong>U</strong> = 32<br>
<strong>UNICODE</strong> = 32<br>
<strong>VERBOSE</strong> = 64<br>
<strong>X</strong> = 64<br>
<strong>__all__</strong> = ['match', 'search', 'sub', 'subn', 'split', 'findall', 'compile', 'purge', 'template', 'escape', 'I', 'L', 'M', 'S', 'X', 'U', 'IGNORECASE', 'LOCALE', 'MULTILINE', 'DOTALL', ...]<br>
<strong>__version__</strong> = '2.2.1'</td></tr></table>
</body></html>
|