Merged revisions 79430 via svnmerge from

svn+ssh://pythondev@svn.python.org/python/trunk

........
  r79430 | brian.curtin | 2010-03-25 18:48:54 -0500 (Thu, 25 Mar 2010) | 2 lines

  Fix #6538. Markup RegexObject and MatchObject as classes. Patch by Ryan Arana.
........
This commit is contained in:
Brian Curtin 2010-03-26 00:39:56 +00:00
parent fa0aebacd9
commit 027e478f3f
1 changed files with 183 additions and 180 deletions

View File

@ -705,11 +705,12 @@ form.
Regular Expression Objects
--------------------------
Compiled regular expression objects support the following methods and
attributes:
.. class:: RegexObject
The :class:`RegexObject` class supports the following methods and attributes:
.. method:: RegexObject.match(string[, pos[, endpos]])
.. method:: RegexObject.match(string[, pos[, endpos]])
If zero or more characters at the beginning of *string* match this regular
expression, return a corresponding :class:`MatchObject` instance. Return
@ -740,7 +741,7 @@ attributes:
<_sre.SRE_Match object at ...>
.. method:: RegexObject.search(string[, pos[, endpos]])
.. method:: RegexObject.search(string[, pos[, endpos]])
Scan through *string* looking for a location where this regular expression
produces a match, and return a corresponding :class:`MatchObject` instance.
@ -751,50 +752,50 @@ attributes:
:meth:`~RegexObject.match` method.
.. method:: RegexObject.split(string, maxsplit=0)
.. method:: RegexObject.split(string[, maxsplit=0])
Identical to the :func:`split` function, using the compiled pattern.
.. method:: RegexObject.findall(string[, pos[, endpos]])
.. method:: RegexObject.findall(string[, pos[, endpos]])
Identical to the :func:`findall` function, using the compiled pattern.
.. method:: RegexObject.finditer(string[, pos[, endpos]])
.. method:: RegexObject.finditer(string[, pos[, endpos]])
Identical to the :func:`finditer` function, using the compiled pattern.
.. method:: RegexObject.sub(repl, string, count=0)
.. method:: RegexObject.sub(repl, string[, count=0])
Identical to the :func:`sub` function, using the compiled pattern.
.. method:: RegexObject.subn(repl, string, count=0)
.. method:: RegexObject.subn(repl, string[, count=0])
Identical to the :func:`subn` function, using the compiled pattern.
.. attribute:: RegexObject.flags
.. attribute:: RegexObject.flags
The flags argument used when the RE object was compiled, or ``0`` if no flags
were provided.
.. attribute:: RegexObject.groups
.. attribute:: RegexObject.groups
The number of capturing groups in the pattern.
.. attribute:: RegexObject.groupindex
.. attribute:: RegexObject.groupindex
A dictionary mapping any symbolic group names defined by ``(?P<id>)`` to group
numbers. The dictionary is empty if no symbolic groups were used in the
pattern.
.. attribute:: RegexObject.pattern
.. attribute:: RegexObject.pattern
The pattern string from which the RE object was compiled.
@ -804,12 +805,14 @@ attributes:
Match Objects
-------------
Match objects always have a boolean value of :const:`True`, so that you can test
whether e.g. :func:`match` resulted in a match with a simple if statement. They
support the following methods and attributes:
.. class:: MatchObject
Match Objects always have a boolean value of :const:`True`, so that you can test
whether e.g. :func:`match` resulted in a match with a simple if statement. They
support the following methods and attributes:
.. method:: MatchObject.expand(template)
.. method:: MatchObject.expand(template)
Return the string obtained by doing backslash substitution on the template
string *template*, as done by the :meth:`~RegexObject.sub` method. Escapes
@ -818,7 +821,7 @@ support the following methods and attributes:
``\g<name>``) are replaced by the contents of the corresponding group.
.. method:: MatchObject.group([group1, ...])
.. method:: MatchObject.group([group1, ...])
Returns one or more subgroups of the match. If there is a single argument, the
result is a single string; if there are multiple arguments, the result is a
@ -868,12 +871,12 @@ support the following methods and attributes:
>>> m.group(1) # Returns only the last match.
'c3'
.. method:: MatchObject.groups(default=None)
Return a tuple containing all the subgroups of the match, from 1 up to however
many groups are in the pattern. The *default* argument is used for groups that
did not participate in the match; it defaults to ``None``.
did not participate in the match; it defaults to ``None``. (Incompatibility
note: in the original Python 1.5 release, if the tuple was one element long, a
string would be returned instead. In later versions (from 1.5.1 on), a
singleton tuple is returned in such cases.)
For example:
@ -892,7 +895,7 @@ support the following methods and attributes:
('24', '0')
.. method:: MatchObject.groupdict(default=None)
.. method:: MatchObject.groupdict([default])
Return a dictionary containing all the *named* subgroups of the match, keyed by
the subgroup name. The *default* argument is used for groups that did not
@ -903,8 +906,8 @@ support the following methods and attributes:
{'first_name': 'Malcolm', 'last_name': 'Reynolds'}
.. method:: MatchObject.start(group=0)
MatchObject.end(group=0)
.. method:: MatchObject.start([group])
MatchObject.end([group])
Return the indices of the start and end of the substring matched by *group*;
*group* defaults to zero (meaning the whole matched substring). Return ``-1`` if
@ -927,28 +930,28 @@ support the following methods and attributes:
'tony@tiger.net'
.. method:: MatchObject.span(group=0)
.. method:: MatchObject.span([group])
For :class:`MatchObject` *m*, return the 2-tuple ``(m.start(group),
m.end(group))``. Note that if *group* did not contribute to the match, this is
``(-1, -1)``. *group* defaults to zero, the entire match.
.. attribute:: MatchObject.pos
.. attribute:: MatchObject.pos
The value of *pos* which was passed to the :meth:`~RegexObject.search` or
:meth:`~RegexObject.match` method of the :class:`RegexObject`. This is the
index into the string at which the RE engine started looking for a match.
.. attribute:: MatchObject.endpos
.. attribute:: MatchObject.endpos
The value of *endpos* which was passed to the :meth:`~RegexObject.search` or
:meth:`~RegexObject.match` method of the :class:`RegexObject`. This is the
index into the string beyond which the RE engine will not go.
.. attribute:: MatchObject.lastindex
.. attribute:: MatchObject.lastindex
The integer index of the last matched capturing group, or ``None`` if no group
was matched at all. For example, the expressions ``(a)b``, ``((a)(b))``, and
@ -957,20 +960,20 @@ support the following methods and attributes:
string.
.. attribute:: MatchObject.lastgroup
.. attribute:: MatchObject.lastgroup
The name of the last matched capturing group, or ``None`` if the group didn't
have a name, or if no group was matched at all.
.. attribute:: MatchObject.re
.. attribute:: MatchObject.re
The regular expression object whose :meth:`~RegexObject.match` or
:meth:`~RegexObject.search` method produced this :class:`MatchObject`
instance.
.. attribute:: MatchObject.string
.. attribute:: MatchObject.string
The string passed to :meth:`~RegexObject.match` or
:meth:`~RegexObject.search`.