mirror of
https://github.com/python/cpython.git
synced 2025-08-21 01:15:03 +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
da779df1d2
commit
b5f062703e
1 changed files with 176 additions and 173 deletions
|
@ -673,11 +673,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
|
||||||
|
@ -708,7 +709,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.
|
||||||
|
@ -719,50 +720,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.
|
||||||
|
|
||||||
|
@ -772,12 +773,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
|
||||||
|
@ -786,7 +789,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
|
||||||
|
@ -837,7 +840,7 @@ support the following methods and attributes:
|
||||||
'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
|
||||||
|
@ -863,7 +866,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
|
||||||
|
@ -874,7 +877,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*;
|
||||||
|
@ -898,28 +901,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
|
||||||
|
@ -928,20 +931,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`.
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue