Commit b869749f authored by Brian Curtin's avatar Brian Curtin

Merged revisions 79434 via svnmerge from

svn+ssh://pythondev@svn.python.org/python/branches/py3k

................
  r79434 | brian.curtin | 2010-03-25 19:39:56 -0500 (Thu, 25 Mar 2010) | 9 lines

  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.
  ........
................
parent adc3691c
...@@ -705,11 +705,12 @@ form. ...@@ -705,11 +705,12 @@ form.
Regular Expression Objects Regular Expression Objects
-------------------------- --------------------------
Compiled regular expression objects support the following methods and .. class:: RegexObject
attributes:
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 If zero or more characters at the beginning of *string* match this regular
expression, return a corresponding :class:`MatchObject` instance. Return expression, return a corresponding :class:`MatchObject` instance. Return
...@@ -740,7 +741,7 @@ attributes: ...@@ -740,7 +741,7 @@ attributes:
<_sre.SRE_Match object at ...> <_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 Scan through *string* looking for a location where this regular expression
produces a match, and return a corresponding :class:`MatchObject` instance. produces a match, and return a corresponding :class:`MatchObject` instance.
...@@ -751,50 +752,50 @@ attributes: ...@@ -751,50 +752,50 @@ attributes:
:meth:`~RegexObject.match` method. :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. 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. 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. 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. 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. 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 The flags argument used when the RE object was compiled, or ``0`` if no flags
were provided. were provided.
.. attribute:: RegexObject.groups .. attribute:: RegexObject.groups
The number of capturing groups in the pattern. 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 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 numbers. The dictionary is empty if no symbolic groups were used in the
pattern. pattern.
.. attribute:: RegexObject.pattern .. attribute:: RegexObject.pattern
The pattern string from which the RE object was compiled. The pattern string from which the RE object was compiled.
...@@ -804,12 +805,14 @@ attributes: ...@@ -804,12 +805,14 @@ attributes:
Match Objects Match Objects
------------- -------------
Match objects always have a boolean value of :const:`True`, so that you can test .. class:: MatchObject
whether e.g. :func:`match` resulted in a match with a simple if statement. They
support the following methods and attributes: 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 Return the string obtained by doing backslash substitution on the template
string *template*, as done by the :meth:`~RegexObject.sub` method. Escapes string *template*, as done by the :meth:`~RegexObject.sub` method. Escapes
...@@ -818,7 +821,7 @@ support the following methods and attributes: ...@@ -818,7 +821,7 @@ support the following methods and attributes:
``\g<name>``) are replaced by the contents of the corresponding group. ``\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 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 result is a single string; if there are multiple arguments, the result is a
...@@ -868,12 +871,14 @@ support the following methods and attributes: ...@@ -868,12 +871,14 @@ support the following methods and attributes:
>>> m.group(1) # Returns only the last match. >>> m.group(1) # Returns only the last match.
'c3' 'c3'
.. method:: MatchObject.groups([default])
.. method:: MatchObject.groups([default])
Return a tuple containing all the subgroups of the match, from 1 up to however 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 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: For example:
...@@ -892,7 +897,7 @@ support the following methods and attributes: ...@@ -892,7 +897,7 @@ support the following methods and attributes:
('24', '0') ('24', '0')
.. method:: MatchObject.groupdict([default]) .. method:: MatchObject.groupdict([default])
Return a dictionary containing all the *named* subgroups of the match, keyed by 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 the subgroup name. The *default* argument is used for groups that did not
...@@ -903,7 +908,7 @@ support the following methods and attributes: ...@@ -903,7 +908,7 @@ support the following methods and attributes:
{'first_name': 'Malcolm', 'last_name': 'Reynolds'} {'first_name': 'Malcolm', 'last_name': 'Reynolds'}
.. method:: MatchObject.start([group]) .. method:: MatchObject.start([group])
MatchObject.end([group]) MatchObject.end([group])
Return the indices of the start and end of the substring matched by *group*; Return the indices of the start and end of the substring matched by *group*;
...@@ -927,28 +932,28 @@ support the following methods and attributes: ...@@ -927,28 +932,28 @@ support the following methods and attributes:
'tony@tiger.net' 'tony@tiger.net'
.. method:: MatchObject.span([group]) .. method:: MatchObject.span([group])
For :class:`MatchObject` *m*, return the 2-tuple ``(m.start(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 m.end(group))``. Note that if *group* did not contribute to the match, this is
``(-1, -1)``. *group* defaults to zero, the entire match. ``(-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 The value of *pos* which was passed to the :meth:`~RegexObject.search` or
:meth:`~RegexObject.match` method of the :class:`RegexObject`. This is the :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. 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 The value of *endpos* which was passed to the :meth:`~RegexObject.search` or
:meth:`~RegexObject.match` method of the :class:`RegexObject`. This is the :meth:`~RegexObject.match` method of the :class:`RegexObject`. This is the
index into the string beyond which the RE engine will not go. 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 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 was matched at all. For example, the expressions ``(a)b``, ``((a)(b))``, and
...@@ -957,20 +962,20 @@ support the following methods and attributes: ...@@ -957,20 +962,20 @@ support the following methods and attributes:
string. string.
.. attribute:: MatchObject.lastgroup .. attribute:: MatchObject.lastgroup
The name of the last matched capturing group, or ``None`` if the group didn't 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. 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 The regular expression object whose :meth:`~RegexObject.match` or
:meth:`~RegexObject.search` method produced this :class:`MatchObject` :meth:`~RegexObject.search` method produced this :class:`MatchObject`
instance. instance.
.. attribute:: MatchObject.string .. attribute:: MatchObject.string
The string passed to :meth:`~RegexObject.match` or The string passed to :meth:`~RegexObject.match` or
:meth:`~RegexObject.search`. :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