<!DOCTYPE html PUBLIC
"-//W3C//DTD HTML 4.0 Transitional//EN">
<link rel=
"STYLESHEET" href=
"lib.css" type='text/css'
/>
<link rel=
"SHORTCUT ICON" href=
"../icons/pyfav.png" type=
"image/png" />
<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=
"node115.html" />
<link rel=
"parent" href=
"module-re.html" />
<link rel=
"next" href=
"match-objects.html" />
<meta name='aesop' content='information'
/>
<title>4.2.4 Regular Expression Objects
</title>
<div id='top-navigation-panel' xml:id='top-navigation-panel'
>
<table align=
"center" width=
"100%" cellpadding=
"0" cellspacing=
"2">
<td class='online-navigation'
><a rel=
"prev" title=
"4.2.3 Module Contents"
href=
"node115.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>
<div class='online-navigation'
>
<b class=
"navlabel">Previous:
</b>
<a class=
"sectref" rel=
"prev" href=
"node115.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>
<!--End of Navigation Panel-->
<H2><A NAME=
"SECTION006240000000000000000"></A><A NAME=
"re-objects"></A>
4.2.4 Regular Expression Objects
Compiled regular expression objects support the following methods and
<dl><dt><table cellpadding=
"0" cellspacing=
"0"><tr valign=
"baseline">
<td><nobr><b><tt id='l2h-
891' xml:id='l2h-
891'
class=
"method">match
</tt></b>(
</nobr></td>
<td><var>string
</var><big>[
</big><var>, pos
</var><big>[
</big><var>,
endpos
</var><big>]
</big><var></var><big>]
</big><var></var>)
</td></tr></table></dt>
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
<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>
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
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
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><dt><table cellpadding=
"0" cellspacing=
"0"><tr valign=
"baseline">
<td><nobr><b><tt id='l2h-
892' xml:id='l2h-
892'
class=
"method">search
</tt></b>(
</nobr></td>
<td><var>string
</var><big>[
</big><var>, pos
</var><big>[
</big><var>,
endpos
</var><big>]
</big><var></var><big>]
</big><var></var>)
</td></tr></table></dt>
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.
The optional
<var>pos
</var> and
<var>endpos
</var> parameters have the same
meaning as for the
<tt class=
"method">match()
</tt> method.
<dl><dt><table cellpadding=
"0" cellspacing=
"0"><tr valign=
"baseline">
<td><nobr><b><tt id='l2h-
893' xml:id='l2h-
893'
class=
"method">split
</tt></b>(
</nobr></td>
<td><var>string
</var><big>[
</big><var>,
maxsplit
<code> =
0</code></var><big>]
</big><var></var>)
</td></tr></table></dt>
Identical to the
<tt class=
"function">split()
</tt> function, using the compiled pattern.
<dl><dt><table cellpadding=
"0" cellspacing=
"0"><tr valign=
"baseline">
<td><nobr><b><tt id='l2h-
894' xml:id='l2h-
894'
class=
"method">findall
</tt></b>(
</nobr></td>
<td><var>string
</var><big>[
</big><var>, pos
</var><big>[
</big><var>,
endpos
</var><big>]
</big><var></var><big>]
</big><var></var>)
</td></tr></table></dt>
Identical to the
<tt class=
"function">findall()
</tt> function, using the compiled pattern.
<dl><dt><table cellpadding=
"0" cellspacing=
"0"><tr valign=
"baseline">
<td><nobr><b><tt id='l2h-
895' xml:id='l2h-
895'
class=
"method">finditer
</tt></b>(
</nobr></td>
<td><var>string
</var><big>[
</big><var>, pos
</var><big>[
</big><var>,
endpos
</var><big>]
</big><var></var><big>]
</big><var></var>)
</td></tr></table></dt>
Identical to the
<tt class=
"function">finditer()
</tt> function, using the compiled pattern.
<dl><dt><table cellpadding=
"0" cellspacing=
"0"><tr valign=
"baseline">
<td><nobr><b><tt id='l2h-
896' xml:id='l2h-
896'
class=
"method">sub
</tt></b>(
</nobr></td>
<td><var>repl, string
</var><big>[
</big><var>, count
<code> =
0</code></var><big>]
</big><var></var>)
</td></tr></table></dt>
Identical to the
<tt class=
"function">sub()
</tt> function, using the compiled pattern.
<dl><dt><table cellpadding=
"0" cellspacing=
"0"><tr valign=
"baseline">
<td><nobr><b><tt id='l2h-
897' xml:id='l2h-
897'
class=
"method">subn
</tt></b>(
</nobr></td>
<td><var>repl, string
</var><big>[
</big><var>,
count
<code> =
0</code></var><big>]
</big><var></var>)
</td></tr></table></dt>
Identical to the
<tt class=
"function">subn()
</tt> function, using the compiled pattern.
<dl><dt><b><tt id='l2h-
898' xml:id='l2h-
898'
class=
"member">flags
</tt></b></dt>
The flags argument used when the RE object was compiled, or
<code>0</code> if no flags were provided.
<dl><dt><b><tt id='l2h-
899' xml:id='l2h-
899'
class=
"member">groupindex
</tt></b></dt>
A dictionary mapping any symbolic group names defined by
<tt class=
"regexp">(?P
<<var>id
</var>>)
</tt> to group numbers. The dictionary is empty if no
symbolic groups were used in the pattern.
<dl><dt><b><tt id='l2h-
900' xml:id='l2h-
900'
class=
"member">pattern
</tt></b></dt>
The pattern string from which the RE object was compiled.
<div class='online-navigation'
>
<table align=
"center" width=
"100%" cellpadding=
"0" cellspacing=
"2">
<td class='online-navigation'
><a rel=
"prev" title=
"4.2.3 Module Contents"
href=
"node115.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>
<div class='online-navigation'
>
<b class=
"navlabel">Previous:
</b>
<a class=
"sectref" rel=
"prev" href=
"node115.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>
<span class=
"release-info">Release
2.4.2, documentation updated on
28 September
2005.
</span>
<!--End of Navigation Panel-->
See
<i><a href=
"about.html">About this document...
</a></i> for information on suggesting changes.