<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<!--Converted with LaTeX2HTML 98.2 beta6 (August 14th, 1998)
original version by:  Nikos Drakos, CBLU, University of Leeds
* revised and updated by:  Marcus Hennecke, Ross Moore, Herb Swan
* with significant contributions from:
  Jens Lippmann, Marek Rouchal, Martin Wilck and others -->
<HTML>
<HEAD>
<TITLE>4.2.4 Regular Expression Objects </TITLE>
<META NAME="description" CONTENT="4.2.4 Regular Expression Objects ">
<META NAME="keywords" CONTENT="lib">
<META NAME="resource-type" CONTENT="document">
<META NAME="distribution" CONTENT="global">
<META HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=iso-8859-1">
<LINK REL="STYLESHEET" HREF="lib.css">
<LINK REL="next" HREF="match-objects.html">
<LINK REL="previous" HREF="Contents_of_Module_re.html">
<LINK REL="up" HREF="module-re.html">
<LINK REL="next" HREF="match-objects.html">
</HEAD>
<BODY bgcolor="#ffffff">
<div class=navigation>
<table align=center width="100%" cellpadding=0 cellspacing=2>
<tr>
<td><A HREF="match-objects.html"><img width=32 height=32 align=bottom border=0 alt="next"
 src="../icons/next.gif"></A></td>
<td><A HREF="module-re.html"><img width=32 height=32 align=bottom border=0 alt="up"
 src="../icons/up.gif"></A></td>
<td><A HREF="Contents_of_Module_re.html"><img width=32 height=32 align=bottom border=0 alt="previous"
 src="../icons/previous.gif"></A></td>
<td align=center bgcolor="#99CCFF" width="100%">
 <b class=title>Python Library Reference</b></td>
<td><A HREF="contents.html"><img width=32 height=32 align=bottom border=0 alt="contents"
 src="../icons/contents.gif"></A></td>
<td><a
 href="modindex.html"><img width=32 height=32 align=bottom border=0 alt="modules"
 src="../icons/modules.gif"></a></td>
<td><A HREF="genindex.html"><img width=32 height=32 align=bottom border=0 alt="index"
 src="../icons/index.gif"></A></td>
</tr></table><b class=navlabel>Next:</b> <span class=sectref><A HREF="match-objects.html">4.2.5 Match Objects</A></span>
<b class=navlabel>Up:</b> <span class=sectref><A HREF="module-re.html">4.2 re  </A></span>
<b class=navlabel>Previous:</b> <span class=sectref><A HREF="Contents_of_Module_re.html">4.2.3 Module Contents</A></span>
<br><hr></div>
<!--End of Navigation Panel-->

<H2><A NAME="SECTION006240000000000000000"></A>
<BR>
4.2.4 Regular Expression Objects 
</H2>

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

<P>
<dl><dt><b><a name="l2h-647"><tt class=method>search</tt></a></b> (<var>string</var><big>[</big><var>, pos</var><big>]</big><big>[</big><var>,
                                        endpos</var><big>]</big>)
<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 <tt>None</tt> 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.
  
  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><b><a name="l2h-648"><tt class=method>match</tt></a></b> (<var>string</var><big>[</big><var>, pos</var><big>]</big><big>[</big><var>,
                                       endpos</var><big>]</big>)
<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 <tt>None</tt> if the string does not
  match the pattern; note that this is different from a zero-length
  match.

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

<P>
The optional second parameter <var>pos</var> gives an index in the string
  where the search is to start; it defaults to <tt>0</tt>.  This is not
  completely equivalent to slicing the string; the <tt>''</tt> 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 <var>endpos</var> will be
  searched for a match.
</dl>

<P>
<dl><dt><b><a name="l2h-649"><tt class=method>split</tt></a></b> (<var>string, </var><big>[</big><var>,
                                       maxsplit<tt> = 0</tt></var><big>]</big>)
<dd>
Identical to the <tt class=function>split()</tt> function, using the compiled pattern.
</dl>

<P>
<dl><dt><b><a name="l2h-650"><tt class=method>findall</tt></a></b> (<var>string</var>)
<dd>
Identical to the <tt class=function>findall()</tt> function, using the compiled pattern.
</dl>

<P>
<dl><dt><b><a name="l2h-651"><tt class=method>sub</tt></a></b> (<var>repl, string</var><big>[</big><var>, count<tt> = 0</tt></var><big>]</big>)
<dd>
Identical to the <tt class=function>sub()</tt> function, using the compiled pattern.
</dl>

<P>
<dl><dt><b><a name="l2h-652"><tt class=method>subn</tt></a></b> (<var>repl, string</var><big>[</big><var>,
                                      count<tt> = 0</tt></var><big>]</big>)
<dd>
Identical to the <tt class=function>subn()</tt> function, using the compiled pattern.
</dl>

<P>
<dl><dt><b><a name="l2h-653"><tt class=member>flags</tt></a></b>
<dd>
The flags argument used when the regex object was compiled, or
<tt>0</tt> if no flags were provided.
</dl>

<P>
<dl><dt><b><a name="l2h-654"><tt class=member>groupindex</tt></a></b>
<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><a name="l2h-655"><tt class=member>pattern</tt></a></b>
<dd>
The pattern string from which the regex object was compiled.
</dl>

<P>
<p>
<div class=navigation><hr><table align=center width="100%" cellpadding=0 cellspacing=2>
<tr>
<td><A HREF="match-objects.html"><img width=32 height=32 align=bottom border=0 alt="next"
 src="../icons/next.gif"></A></td>
<td><A HREF="module-re.html"><img width=32 height=32 align=bottom border=0 alt="up"
 src="../icons/up.gif"></A></td>
<td><A HREF="Contents_of_Module_re.html"><img width=32 height=32 align=bottom border=0 alt="previous"
 src="../icons/previous.gif"></A></td>
<td align=center bgcolor="#99CCFF" width="100%">
 <b class=title>Python Library Reference</b></td>
<td><A HREF="contents.html"><img width=32 height=32 align=bottom border=0 alt="contents"
 src="../icons/contents.gif"></A></td>
<td><a
 href="modindex.html"><img width=32 height=32 align=bottom border=0 alt="modules"
 src="../icons/modules.gif"></a></td>
<td><A HREF="genindex.html"><img width=32 height=32 align=bottom border=0 alt="index"
 src="../icons/index.gif"></A></td>
</tr></table><b class=navlabel>Next:</b> <span class=sectref><A HREF="match-objects.html">4.2.5 Match Objects</A></span>
<b class=navlabel>Up:</b> <span class=sectref><A HREF="module-re.html">4.2 re  </A></span>
<b class=navlabel>Previous:</b> <span class=sectref><A HREF="Contents_of_Module_re.html">4.2.3 Module Contents</A></span>
</div>
<!--End of Navigation Panel-->
<ADDRESS>
<hr>Send comments on this document to <a href="mailto:python-docs@python.org">python-docs@python.org</a>.
</ADDRESS>
</BODY>
</HTML>
