Commit fbe51997 authored by Brian Curtin's avatar Brian Curtin

Fix #6538. Markup RegexObject and MatchObject as classes. Patch by Ryan Arana.

parent 06638735
......@@ -685,11 +685,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
......@@ -720,7 +721,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.
......@@ -731,50 +732,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.
......@@ -784,12 +785,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
......@@ -798,7 +801,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
......@@ -849,7 +852,7 @@ support the following methods and attributes:
'c3'
.. method:: MatchObject.groups([default])
.. method:: MatchObject.groups([default])
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
......@@ -875,7 +878,7 @@ support the following methods and attributes:
('24', '0')
.. method:: MatchObject.groupdict([default])
.. 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
......@@ -886,7 +889,7 @@ support the following methods and attributes:
{'first_name': 'Malcolm', 'last_name': 'Reynolds'}
.. method:: MatchObject.start([group])
.. method:: MatchObject.start([group])
MatchObject.end([group])
Return the indices of the start and end of the substring matched by *group*;
......@@ -910,28 +913,28 @@ support the following methods and attributes:
'tony@tiger.net'
.. method:: MatchObject.span([group])
.. 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
......@@ -940,20 +943,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`.
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment