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 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361
|
<?xml version="1.0" encoding="iso-8859-1"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<title>sre</title>
<link rel="stylesheet" href="epydoc.css" type="text/css"></link>
</head>
<body bgcolor="white" text="black" link="blue" vlink="#204080"
alink="#204080">
<!-- =========== START OF NAVBAR =========== -->
<table class="navbar" border="0" width="100%" cellpadding="0" bgcolor="#a0c0ff" cellspacing="0">
<tr valign="center">
<th bgcolor="#70b0f0" class="navselect"> Home </th>
<th class="navbar"> <a class="navbar" href="trees.html">Trees</a> </th>
<th class="navbar"> <a class="navbar" href="indices.html">Index</a> </th>
<th class="navbar"> <a class="navbar" href="help.html">Help</a> </th>
<th class="navbar" align="right" width="100%">
<table border="0" cellpadding="0" cellspacing="0">
<tr><th class="navbar" align="center">
<p class="nomargin">
<a class="navbar" target="_top" href="http://epydoc.sourceforge.net">epydoc examples</a>
</p></th></tr></table>
</th>
</tr>
</table>
<table width="100%" cellpadding="0" cellspacing="0">
<tr valign="top">
<td width="100%">
<font size="-1"><b class="breadcrumbs">
Module sre
</b></font></br>
</td>
<td><table cellpadding="0" cellspacing="0">
<tr><td align="right"><font size="-2">[<a href="frames.html"target="_top">frames</a> | <a href="sre-module.html" target="_top">no frames</a>]</font></td></tr>
</table></td>
</tr></table>
<!-- =========== START OF MODULE DESCRIPTION =========== -->
<h2 class="module">Module sre</h2>
<pre class="literalblock">
Support for regular expressions (RE).
This module provides regular expression matching operations similar to
those found in Perl. It supports both 8-bit and Unicode strings; both
the pattern and the strings being processed can contain null bytes and
characters outside the US ASCII range.
Regular expressions can contain both special and ordinary characters.
Most ordinary characters, like "A", "a", or "0", are the simplest
regular expressions; they simply match themselves. You can
concatenate ordinary characters, so last matches the string 'last'.
The special characters are:
"." Matches any character except a newline.
"^" Matches the start of the string.
"$" Matches the end of the string.
"*" Matches 0 or more (greedy) repetitions of the preceding RE.
Greedy means that it will match as many repetitions as possible.
"+" Matches 1 or more (greedy) repetitions of the preceding RE.
"?" Matches 0 or 1 (greedy) of the preceding RE.
*?,+?,?? Non-greedy versions of the previous three special characters.
{m,n} Matches from m to n repetitions of the preceding RE.
{m,n}? Non-greedy version of the above.
"\\" Either escapes special characters or signals a special sequence.
[] Indicates a set of characters.
A "^" as the first character indicates a complementing set.
"|" A|B, creates an RE that will match either A or B.
(...) Matches the RE inside the parentheses.
The contents can be retrieved or matched later in the string.
(?iLmsux) Set the I, L, M, S, U, or X flag for the RE (see below).
(?:...) Non-grouping version of regular parentheses.
(?P<name>...) The substring matched by the group is accessible by name.
(?P=name) Matches the text matched earlier by the group named name.
(?#...) A comment; ignored.
(?=...) Matches if ... matches next, but doesn't consume the string.
(?!...) Matches if ... doesn't match next.
The special sequences consist of "\\" and a character from the list
below. If the ordinary character is not on the list, then the
resulting RE will match the second character.
\number Matches the contents of the group of the same number.
\A Matches only at the start of the string.
\Z Matches only at the end of the string.
\b Matches the empty string, but only at the start or end of a word.
\B Matches the empty string, but not at the start or end of a word.
\d Matches any decimal digit; equivalent to the set [0-9].
\D Matches any non-digit character; equivalent to the set [^0-9].
\s Matches any whitespace character; equivalent to [ \t\n\r\f\v].
\S Matches any non-whitespace character; equiv. to [^ \t\n\r\f\v].
\w Matches any alphanumeric character; equivalent to [a-zA-Z0-9_].
With LOCALE, it will match the set [0-9_] plus characters defined
as letters for the current locale.
\W Matches the complement of \w.
\\ Matches a literal backslash.
This module exports the following functions:
match Match a regular expression pattern to the beginning of a string.
search Search a string for the presence of a pattern.
sub Substitute occurrences of a pattern found in a string.
subn Same as sub, but also return the number of substitutions made.
split Split a string by the occurrences of a pattern.
findall Find all occurrences of a pattern in a string.
compile Compile a pattern into a RegexObject.
purge Clear the regular expression cache.
escape Backslash all non-alphanumerics in a string.
Some of the functions in this module takes flags as optional parameters:
I IGNORECASE Perform case-insensitive matching.
L LOCALE Make \w, \W, \b, \B, dependent on the current locale.
M MULTILINE "^" matches the beginning of lines as well as the string.
"$" matches the end of lines as well as the string.
S DOTALL "." matches any character at all, including the newline.
X VERBOSE Ignore whitespace and comments for nicer looking RE's.
U UNICODE Make \w, \W, \b, \B, dependent on the Unicode locale.
This module also defines an exception 'error'.
</pre>
<hr/>
<!-- =========== START OF FUNCTION SUMMARY =========== -->
<table class="summary" border="1" cellpadding="3" cellspacing="0" width="100%" bgcolor="white">
<tr bgcolor="#70b0f0" class="summary">
<th colspan="2">Function Summary</th></tr>
<tr><td align="right" valign="top" width="15%"><font size="-1"> </font></td>
<td><code><span class="summary-sig"><a href="sre-module.html#compile" class="summary-sig-name"><code>compile</code></a>(<span class=summary-sig-arg>pattern</span>,
<span class=summary-sig-arg>flags</span>)</span></code>
<br />
Compile a regular expression pattern, returning a pattern object.</td></tr>
<tr><td align="right" valign="top" width="15%"><font size="-1"> </font></td>
<td><code><span class="summary-sig"><a href="sre-module.html#escape" class="summary-sig-name"><code>escape</code></a>(<span class=summary-sig-arg>pattern</span>)</span></code>
<br />
Escape all non-alphanumeric characters in pattern.</td></tr>
<tr><td align="right" valign="top" width="15%"><font size="-1"> </font></td>
<td><code><span class="summary-sig"><a href="sre-module.html#findall" class="summary-sig-name"><code>findall</code></a>(<span class=summary-sig-arg>pattern</span>,
<span class=summary-sig-arg>string</span>)</span></code>
<br />
Return a list of all non-overlapping matches in the string.</td></tr>
<tr><td align="right" valign="top" width="15%"><font size="-1"> </font></td>
<td><code><span class="summary-sig"><a href="sre-module.html#match" class="summary-sig-name"><code>match</code></a>(<span class=summary-sig-arg>pattern</span>,
<span class=summary-sig-arg>string</span>,
<span class=summary-sig-arg>flags</span>)</span></code>
<br />
Try to apply the pattern at the start of the string, returning
a match object, or None if no match was found.</td></tr>
<tr><td align="right" valign="top" width="15%"><font size="-1"> </font></td>
<td><code><span class="summary-sig"><a href="sre-module.html#purge" class="summary-sig-name"><code>purge</code></a>()</span></code>
<br />
Clear the regular expression cache...</td></tr>
<tr><td align="right" valign="top" width="15%"><font size="-1"> </font></td>
<td><code><span class="summary-sig"><a href="sre-module.html#search" class="summary-sig-name"><code>search</code></a>(<span class=summary-sig-arg>pattern</span>,
<span class=summary-sig-arg>string</span>,
<span class=summary-sig-arg>flags</span>)</span></code>
<br />
Scan through string looking for a match to the pattern, returning
a match object, or None if no match was found.</td></tr>
<tr><td align="right" valign="top" width="15%"><font size="-1"> </font></td>
<td><code><span class="summary-sig"><a href="sre-module.html#split" class="summary-sig-name"><code>split</code></a>(<span class=summary-sig-arg>pattern</span>,
<span class=summary-sig-arg>string</span>,
<span class=summary-sig-arg>maxsplit</span>)</span></code>
<br />
Split the source string by the occurrences of the pattern,
returning a list containing the resulting substrings.</td></tr>
<tr><td align="right" valign="top" width="15%"><font size="-1"> </font></td>
<td><code><span class="summary-sig"><a href="sre-module.html#sub" class="summary-sig-name"><code>sub</code></a>(<span class=summary-sig-arg>pattern</span>,
<span class=summary-sig-arg>repl</span>,
<span class=summary-sig-arg>string</span>,
<span class=summary-sig-arg>count</span>)</span></code>
<br />
Return the string obtained by replacing the leftmost...</td></tr>
<tr><td align="right" valign="top" width="15%"><font size="-1"> </font></td>
<td><code><span class="summary-sig"><a href="sre-module.html#subn" class="summary-sig-name"><code>subn</code></a>(<span class=summary-sig-arg>pattern</span>,
<span class=summary-sig-arg>repl</span>,
<span class=summary-sig-arg>string</span>,
<span class=summary-sig-arg>count</span>)</span></code>
<br />
Return a 2-tuple containing (new_string, number).</td></tr>
<tr><td align="right" valign="top" width="15%"><font size="-1"> </font></td>
<td><code><span class="summary-sig"><a href="sre-module.html#template" class="summary-sig-name"><code>template</code></a>(<span class=summary-sig-arg>pattern</span>,
<span class=summary-sig-arg>flags</span>)</span></code>
<br />
Compile a template pattern, returning a pattern object...</td></tr>
</table><br />
<!-- =========== START OF FUNCTION DETAILS =========== -->
<table class="details" border="1" cellpadding="3" cellspacing="0" width="100%" bgcolor="white">
<tr bgcolor="#70b0f0" class="details">
<th colspan="2">Function Details</th></tr>
</table>
<a name="compile"></a>
<table width="100%" class="func-details" bgcolor="#e0e0e0"><tr><td>
<h3><span class="sig"><span class="sig-name">compile</span>(<span class=sig-arg>pattern</span>,
<span class=sig-arg>flags</span>=<span class=sig-default>0</span>)</span>
</h3>
<pre class="literalblock">
Compile a regular expression pattern, returning a pattern object.
</pre>
<dl><dt></dt><dd>
</dd></dl>
</td></tr></table>
<a name="escape"></a>
<table width="100%" class="func-details" bgcolor="#e0e0e0"><tr><td>
<h3><span class="sig"><span class="sig-name">escape</span>(<span class=sig-arg>pattern</span>)</span>
</h3>
<pre class="literalblock">
Escape all non-alphanumeric characters in pattern.
</pre>
<dl><dt></dt><dd>
</dd></dl>
</td></tr></table>
<a name="findall"></a>
<table width="100%" class="func-details" bgcolor="#e0e0e0"><tr><td>
<h3><span class="sig"><span class="sig-name">findall</span>(<span class=sig-arg>pattern</span>,
<span class=sig-arg>string</span>)</span>
</h3>
<pre class="literalblock">
Return a list of all non-overlapping matches in the string.
If one or more groups are present in the pattern, return a
list of groups; this will be a list of tuples if the pattern
has more than one group.
Empty matches are included in the result.
</pre>
<dl><dt></dt><dd>
</dd></dl>
</td></tr></table>
<a name="match"></a>
<table width="100%" class="func-details" bgcolor="#e0e0e0"><tr><td>
<h3><span class="sig"><span class="sig-name">match</span>(<span class=sig-arg>pattern</span>,
<span class=sig-arg>string</span>,
<span class=sig-arg>flags</span>=<span class=sig-default>0</span>)</span>
</h3>
<pre class="literalblock">
Try to apply the pattern at the start of the string, returning
a match object, or None if no match was found.
</pre>
<dl><dt></dt><dd>
</dd></dl>
</td></tr></table>
<a name="purge"></a>
<table width="100%" class="func-details" bgcolor="#e0e0e0"><tr><td>
<h3><span class="sig"><span class="sig-name">purge</span>()</span>
</h3>
<pre class="literalblock">
Clear the regular expression cache
</pre>
<dl><dt></dt><dd>
</dd></dl>
</td></tr></table>
<a name="search"></a>
<table width="100%" class="func-details" bgcolor="#e0e0e0"><tr><td>
<h3><span class="sig"><span class="sig-name">search</span>(<span class=sig-arg>pattern</span>,
<span class=sig-arg>string</span>,
<span class=sig-arg>flags</span>=<span class=sig-default>0</span>)</span>
</h3>
<pre class="literalblock">
Scan through string looking for a match to the pattern, returning
a match object, or None if no match was found.
</pre>
<dl><dt></dt><dd>
</dd></dl>
</td></tr></table>
<a name="split"></a>
<table width="100%" class="func-details" bgcolor="#e0e0e0"><tr><td>
<h3><span class="sig"><span class="sig-name">split</span>(<span class=sig-arg>pattern</span>,
<span class=sig-arg>string</span>,
<span class=sig-arg>maxsplit</span>=<span class=sig-default>0</span>)</span>
</h3>
<pre class="literalblock">
Split the source string by the occurrences of the pattern,
returning a list containing the resulting substrings.
</pre>
<dl><dt></dt><dd>
</dd></dl>
</td></tr></table>
<a name="sub"></a>
<table width="100%" class="func-details" bgcolor="#e0e0e0"><tr><td>
<h3><span class="sig"><span class="sig-name">sub</span>(<span class=sig-arg>pattern</span>,
<span class=sig-arg>repl</span>,
<span class=sig-arg>string</span>,
<span class=sig-arg>count</span>=<span class=sig-default>0</span>)</span>
</h3>
<pre class="literalblock">
Return the string obtained by replacing the leftmost
non-overlapping occurrences of the pattern in string by the
replacement repl
</pre>
<dl><dt></dt><dd>
</dd></dl>
</td></tr></table>
<a name="subn"></a>
<table width="100%" class="func-details" bgcolor="#e0e0e0"><tr><td>
<h3><span class="sig"><span class="sig-name">subn</span>(<span class=sig-arg>pattern</span>,
<span class=sig-arg>repl</span>,
<span class=sig-arg>string</span>,
<span class=sig-arg>count</span>=<span class=sig-default>0</span>)</span>
</h3>
<pre class="literalblock">
Return a 2-tuple containing (new_string, number).
new_string is the string obtained by replacing the leftmost
non-overlapping occurrences of the pattern in the source
string by the replacement repl. number is the number of
substitutions that were made.
</pre>
<dl><dt></dt><dd>
</dd></dl>
</td></tr></table>
<a name="template"></a>
<table width="100%" class="func-details" bgcolor="#e0e0e0"><tr><td>
<h3><span class="sig"><span class="sig-name">template</span>(<span class=sig-arg>pattern</span>,
<span class=sig-arg>flags</span>=<span class=sig-default>0</span>)</span>
</h3>
<pre class="literalblock">
Compile a template pattern, returning a pattern object
</pre>
<dl><dt></dt><dd>
</dd></dl>
</td></tr></table>
<br />
<!-- =========== START OF NAVBAR =========== -->
<table class="navbar" border="0" width="100%" cellpadding="0" bgcolor="#a0c0ff" cellspacing="0">
<tr valign="center">
<th bgcolor="#70b0f0" class="navselect"> Home </th>
<th class="navbar"> <a class="navbar" href="trees.html">Trees</a> </th>
<th class="navbar"> <a class="navbar" href="indices.html">Index</a> </th>
<th class="navbar"> <a class="navbar" href="help.html">Help</a> </th>
<th class="navbar" align="right" width="100%">
<table border="0" cellpadding="0" cellspacing="0">
<tr><th class="navbar" align="center">
<p class="nomargin">
<a class="navbar" target="_top" href="http://epydoc.sourceforge.net">epydoc examples</a>
</p></th></tr></table>
</th>
</tr>
</table>
<table border="0" cellpadding="0" cellspacing="0" width="100%">
<tr>
<td align="left"><font size="-2">Generated by Epydoc 2.1 on Sat Mar 20 17:46:24 2004</font></td>
<td align="right"><a href="http://epydoc.sourceforge.net"
><font size="-2">http://epydoc.sf.net</font></a></td>
</tr>
</table>
</body>
</html>
|