Sophie

Sophie

distrib > Mandriva > 10.1 > i586 > by-pkgid > ccf83290023404568bb21aa0163b385f > files > 910

python-docs-2.3.4-6.2.101mdk.i586.rpm

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html>
<head>
<link rel="STYLESHEET" href="lib.css" type='text/css' />
<link rel="SHORTCUT ICON" href="../icons/pyfav.gif" />
<link rel='start' href='../index.html' title='Python Documentation Index' />
<link rel="first" href="lib.html" title='Python Library Reference' />
<link rel='contents' href='contents.html' title="Contents" />
<link rel='index' href='genindex.html' title='Index' />
<link rel='last' href='about.html' title='About this document...' />
<link rel='help' href='about.html' title='About this document...' />
<LINK rel="next" href="match-objects.html">
<LINK rel="prev" href="node106.html">
<LINK rel="parent" href="module-re.html">
<LINK rel="next" href="match-objects.html">
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<meta name='aesop' content='information' />
<META name="description" content="Regular Expression Objects ">
<META name="keywords" content="lib">
<META name="resource-type" content="document">
<META name="distribution" content="global">
<title>4.2.4 Regular Expression Objects </title>
</head>
<body>
<DIV CLASS="navigation">
<div id='top-navigation-panel'>
<table align="center" width="100%" cellpadding="0" cellspacing="2">
<tr>
<td class='online-navigation'><a rel="prev" title="4.2.3 Module Contents" 
  href="node106.html"><img src='../icons/previous.png'
  border='0' height='32'  alt='Previous Page' width='32' /></A></td>
<td class='online-navigation'><a rel="parent" title="4.2 re  " 
  href="module-re.html"><img src='../icons/up.png'
  border='0' height='32'  alt='Up One Level' width='32' /></A></td>
<td class='online-navigation'><a rel="next" title="4.2.5 Match Objects" 
  href="match-objects.html"><img src='../icons/next.png'
  border='0' height='32'  alt='Next Page' width='32' /></A></td>
<td align="center" width="100%">Python Library Reference</td>
<td class='online-navigation'><a rel="contents" title="Table of Contents" 
  href="contents.html"><img src='../icons/contents.png'
  border='0' height='32'  alt='Contents' width='32' /></A></td>
<td class='online-navigation'><a href="modindex.html" title="Module Index"><img src='../icons/modules.png'
  border='0' height='32'  alt='Module Index' width='32' /></a></td>
<td class='online-navigation'><a rel="index" title="Index" 
  href="genindex.html"><img src='../icons/index.png'
  border='0' height='32'  alt='Index' width='32' /></A></td>
</tr></table>
<div class='online-navigation'>
<b class="navlabel">Previous:</b>
<a class="sectref" rel="prev" href="node106.html">4.2.3 Module Contents</A>
<b class="navlabel">Up:</b>
<a class="sectref" rel="parent" href="module-re.html">4.2 re  </A>
<b class="navlabel">Next:</b>
<a class="sectref" rel="next" href="match-objects.html">4.2.5 Match Objects</A>
</div>
<hr /></div>
</DIV>
<!--End of Navigation Panel-->

<H2><A NAME="SECTION006240000000000000000"><!--x--></A><A NAME="re-objects"><!--z--></A>
<BR>
4.2.4 Regular Expression Objects 
</H2>

<P>
Compiled regular expression objects support the following methods and
attributes:

<P>
<dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline">
  <td><nobr><b><tt id='l2h-854' class="method">match</tt></b>(</nobr></td>
  <td><var>string</var><big>[</big><var>, pos</var><big>[</big><var>,
                                       endpos</var><big>]</big><big>]</big>)</td></tr></table></dt>
<dd>
  If zero or more characters at the beginning of <var>string</var> match
  this regular expression, return a corresponding
  <tt class="class">MatchObject</tt> instance.  Return <code>None</code> if the string does not
  match the pattern; note that this is different from a zero-length
  match.

<P>
<span class="note"><b class="label">Note:</b>
If you want to locate a match anywhere in
  <var>string</var>, use <tt class="method">search()</tt> instead.</span>

<P>
The optional second parameter <var>pos</var> gives an index in the string
  where the search is to start; it defaults to <code>0</code>.  This is not
  completely equivalent to slicing the string; the
  <code>'^'</code> pattern
  character matches at the real beginning of the string and at positions
  just after a newline, but not necessarily at the index where the search
  is to start.

<P>
The optional parameter <var>endpos</var> limits how far the string will
  be searched; it will be as if the string is <var>endpos</var> characters
  long, so only the characters from <var>pos</var> to <code><var>endpos</var> -
  1</code> will be searched for a match.  If <var>endpos</var> is less than
  <var>pos</var>, no match will be found, otherwise, if <var>rx</var> is a
  compiled regular expression object,
  <code><var>rx</var>.match(<var>string</var>, 0, 50)</code> is equivalent to
  <code><var>rx</var>.match(<var>string</var>[:50], 0)</code>.
</dl>

<P>
<dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline">
  <td><nobr><b><tt id='l2h-855' class="method">search</tt></b>(</nobr></td>
  <td><var>string</var><big>[</big><var>, pos</var><big>[</big><var>,
                                        endpos</var><big>]</big><big>]</big>)</td></tr></table></dt>
<dd>
  Scan through <var>string</var> looking for a location where this regular
  expression produces a match, and return a
  corresponding <tt class="class">MatchObject</tt> instance.  Return <code>None</code> if no
  position in the string matches the pattern; note that this is
  different from finding a zero-length match at some point in the string.

<P>
The optional <var>pos</var> and <var>endpos</var> parameters have the same
  meaning as for the <tt class="method">match()</tt> method.
</dl>

<P>
<dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline">
  <td><nobr><b><tt id='l2h-856' class="method">split</tt></b>(</nobr></td>
  <td><var>string</var><big>[</big><var>,
                                       maxsplit<code> = 0</code></var><big>]</big>)</td></tr></table></dt>
<dd>
Identical to the <tt class="function">split()</tt> function, using the compiled pattern.
</dl>

<P>
<dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline">
  <td><nobr><b><tt id='l2h-857' class="method">findall</tt></b>(</nobr></td>
  <td><var>string</var>)</td></tr></table></dt>
<dd>
Identical to the <tt class="function">findall()</tt> function, using the compiled pattern.
</dl>

<P>
<dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline">
  <td><nobr><b><tt id='l2h-858' class="method">finditer</tt></b>(</nobr></td>
  <td><var>string</var>)</td></tr></table></dt>
<dd>
Identical to the <tt class="function">finditer()</tt> function, using the compiled pattern.
</dl>

<P>
<dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline">
  <td><nobr><b><tt id='l2h-859' class="method">sub</tt></b>(</nobr></td>
  <td><var>repl, string</var><big>[</big><var>, count<code> = 0</code></var><big>]</big>)</td></tr></table></dt>
<dd>
Identical to the <tt class="function">sub()</tt> function, using the compiled pattern.
</dl>

<P>
<dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline">
  <td><nobr><b><tt id='l2h-860' class="method">subn</tt></b>(</nobr></td>
  <td><var>repl, string</var><big>[</big><var>,
                                      count<code> = 0</code></var><big>]</big>)</td></tr></table></dt>
<dd>
Identical to the <tt class="function">subn()</tt> function, using the compiled pattern.
</dl>

<P>
<dl><dt><b><tt id='l2h-861' class="member">flags</tt></b></dt>
<dd>
The flags argument used when the RE object was compiled, or
<code>0</code> if no flags were provided.
</dl>

<P>
<dl><dt><b><tt id='l2h-862' class="member">groupindex</tt></b></dt>
<dd>
A dictionary mapping any symbolic group names defined by
<tt class="regexp">(?P&lt;<var>id</var>&gt;)</tt> to group numbers.  The dictionary is empty if no
symbolic groups were used in the pattern.
</dl>

<P>
<dl><dt><b><tt id='l2h-863' class="member">pattern</tt></b></dt>
<dd>
The pattern string from which the RE object was compiled.
</dl>

<P>

<DIV CLASS="navigation">
<div class='online-navigation'><hr />
<table align="center" width="100%" cellpadding="0" cellspacing="2">
<tr>
<td class='online-navigation'><a rel="prev" title="4.2.3 Module Contents" 
  rel="prev" title="4.2.3 Module Contents" 
  href="node106.html"><img src='../icons/previous.png'
  border='0' height='32'  alt='Previous Page' width='32' /></A></td>
<td class='online-navigation'><a rel="parent" title="4.2 re  " 
  rel="parent" title="4.2 re  " 
  href="module-re.html"><img src='../icons/up.png'
  border='0' height='32'  alt='Up One Level' width='32' /></A></td>
<td class='online-navigation'><a rel="next" title="4.2.5 Match Objects" 
  rel="next" title="4.2.5 Match Objects" 
  href="match-objects.html"><img src='../icons/next.png'
  border='0' height='32'  alt='Next Page' width='32' /></A></td>
<td align="center" width="100%">Python Library Reference</td>
<td class='online-navigation'><a rel="contents" title="Table of Contents" 
  rel="contents" title="Table of Contents" 
  href="contents.html"><img src='../icons/contents.png'
  border='0' height='32'  alt='Contents' width='32' /></A></td>
<td class='online-navigation'><a href="modindex.html" title="Module Index"><img src='../icons/modules.png'
  border='0' height='32'  alt='Module Index' width='32' /></a></td>
<td class='online-navigation'><a rel="index" title="Index" 
  rel="index" title="Index" 
  href="genindex.html"><img src='../icons/index.png'
  border='0' height='32'  alt='Index' width='32' /></A></td>
</tr></table>
<div class='online-navigation'>
<b class="navlabel">Previous:</b>
<a class="sectref" rel="prev" href="node106.html">4.2.3 Module Contents</A>
<b class="navlabel">Up:</b>
<a class="sectref" rel="parent" href="module-re.html">4.2 re  </A>
<b class="navlabel">Next:</b>
<a class="sectref" rel="next" href="match-objects.html">4.2.5 Match Objects</A>
</div>
</div>
<hr />
<span class="release-info">Release 2.3.4, documentation updated on May 20, 2004.</span>
</DIV>
<!--End of Navigation Panel-->
<ADDRESS>
See <i><a href="about.html">About this document...</a></i> for information on suggesting changes.
</ADDRESS>
</BODY>
</HTML>