mirror of
https://github.com/python/cpython.git
synced 2025-09-25 09:50:37 +00:00
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:
parent
fa0aebacd9
commit
027e478f3f
1 changed files with 183 additions and 180 deletions
|
@ -705,8 +705,9 @@ 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]])
|
||||||
|
@ -751,7 +752,7 @@ 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.
|
||||||
|
|
||||||
|
@ -766,12 +767,12 @@ attributes:
|
||||||
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.
|
||||||
|
|
||||||
|
@ -804,7 +805,9 @@ attributes:
|
||||||
Match Objects
|
Match Objects
|
||||||
-------------
|
-------------
|
||||||
|
|
||||||
Match objects always have a boolean value of :const:`True`, so that you can test
|
.. 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
|
whether e.g. :func:`match` resulted in a match with a simple if statement. They
|
||||||
support the following methods and attributes:
|
support the following methods and attributes:
|
||||||
|
|
||||||
|
@ -868,12 +871,12 @@ 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=None)
|
|
||||||
|
|
||||||
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 +895,7 @@ support the following methods and attributes:
|
||||||
('24', '0')
|
('24', '0')
|
||||||
|
|
||||||
|
|
||||||
.. method:: MatchObject.groupdict(default=None)
|
.. 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,8 +906,8 @@ support the following methods and attributes:
|
||||||
{'first_name': 'Malcolm', 'last_name': 'Reynolds'}
|
{'first_name': 'Malcolm', 'last_name': 'Reynolds'}
|
||||||
|
|
||||||
|
|
||||||
.. method:: MatchObject.start(group=0)
|
.. method:: MatchObject.start([group])
|
||||||
MatchObject.end(group=0)
|
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*;
|
||||||
*group* defaults to zero (meaning the whole matched substring). Return ``-1`` if
|
*group* defaults to zero (meaning the whole matched substring). Return ``-1`` if
|
||||||
|
@ -927,7 +930,7 @@ support the following methods and attributes:
|
||||||
'tony@tiger.net'
|
'tony@tiger.net'
|
||||||
|
|
||||||
|
|
||||||
.. method:: MatchObject.span(group=0)
|
.. 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
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue