mirror of
https://github.com/python/cpython.git
synced 2025-10-03 21:55:41 +00:00
Put docs for RegexObject.search() before RegexObject.match() to mirror re.search() and re.match() order.
This commit is contained in:
parent
ac94f4f716
commit
b1a14051b7
1 changed files with 27 additions and 23 deletions
|
@ -689,18 +689,12 @@ Regular Expression Objects
|
||||||
|
|
||||||
The :class:`RegexObject` class supports the following methods and attributes:
|
The :class:`RegexObject` class supports the following methods and attributes:
|
||||||
|
|
||||||
|
.. method:: RegexObject.search(string[, pos[, endpos]])
|
||||||
|
|
||||||
.. method:: RegexObject.match(string[, pos[, endpos]])
|
Scan through *string* looking for a location where this regular expression
|
||||||
|
produces a match, and return a corresponding :class:`MatchObject` instance.
|
||||||
If zero or more characters at the beginning of *string* match this regular
|
Return ``None`` if no position in the string matches the pattern; note that this
|
||||||
expression, return a corresponding :class:`MatchObject` instance. Return
|
is different from finding a zero-length match at some point in the string.
|
||||||
``None`` if the string does not match the pattern; note that this is different
|
|
||||||
from a zero-length match.
|
|
||||||
|
|
||||||
.. note::
|
|
||||||
|
|
||||||
If you want to locate a match anywhere in *string*, use
|
|
||||||
:meth:`~RegexObject.search` instead.
|
|
||||||
|
|
||||||
The optional second parameter *pos* gives an index in the string where the
|
The optional second parameter *pos* gives an index in the string where the
|
||||||
search is to start; it defaults to ``0``. This is not completely equivalent to
|
search is to start; it defaults to ``0``. This is not completely equivalent to
|
||||||
|
@ -712,24 +706,34 @@ Regular Expression Objects
|
||||||
will be as if the string is *endpos* characters long, so only the characters
|
will be as if the string is *endpos* characters long, so only the characters
|
||||||
from *pos* to ``endpos - 1`` will be searched for a match. If *endpos* is less
|
from *pos* to ``endpos - 1`` will be searched for a match. If *endpos* is less
|
||||||
than *pos*, no match will be found, otherwise, if *rx* is a compiled regular
|
than *pos*, no match will be found, otherwise, if *rx* is a compiled regular
|
||||||
expression object, ``rx.match(string, 0, 50)`` is equivalent to
|
expression object, ``rx.search(string, 0, 50)`` is equivalent to
|
||||||
``rx.match(string[:50], 0)``.
|
``rx.search(string[:50], 0)``.
|
||||||
|
|
||||||
>>> pattern = re.compile("o")
|
>>> pattern = re.compile("d")
|
||||||
>>> pattern.match("dog") # No match as "o" is not at the start of "dog."
|
>>> pattern.search("dog") # Match at index 0
|
||||||
>>> pattern.match("dog", 1) # Match as "o" is the 2nd character of "dog".
|
<_sre.SRE_Match object at ...>
|
||||||
<_sre.SRE_Match object at ...>
|
>>> pattern.search("dog", 1) # No match; search doesn't include the "d"
|
||||||
|
|
||||||
|
|
||||||
.. method:: RegexObject.search(string[, pos[, endpos]])
|
.. method:: RegexObject.match(string[, pos[, endpos]])
|
||||||
|
|
||||||
Scan through *string* looking for a location where this regular expression
|
If zero or more characters at the *beginning* of *string* match this regular
|
||||||
produces a match, and return a corresponding :class:`MatchObject` instance.
|
expression, return a corresponding :class:`MatchObject` instance. Return
|
||||||
Return ``None`` if no position in the string matches the pattern; note that this
|
``None`` if the string does not match the pattern; note that this is different
|
||||||
is different from finding a zero-length match at some point in the string.
|
from a zero-length match.
|
||||||
|
|
||||||
The optional *pos* and *endpos* parameters have the same meaning as for the
|
The optional *pos* and *endpos* parameters have the same meaning as for the
|
||||||
:meth:`~RegexObject.match` method.
|
:meth:`~RegexObject.search` method.
|
||||||
|
|
||||||
|
.. note::
|
||||||
|
|
||||||
|
If you want to locate a match anywhere in *string*, use
|
||||||
|
:meth:`~RegexObject.search` instead.
|
||||||
|
|
||||||
|
>>> pattern = re.compile("o")
|
||||||
|
>>> pattern.match("dog") # No match as "o" is not at the start of "dog".
|
||||||
|
>>> pattern.match("dog", 1) # Match as "o" is the 2nd character of "dog".
|
||||||
|
<_sre.SRE_Match object at ...>
|
||||||
|
|
||||||
|
|
||||||
.. method:: RegexObject.split(string[, maxsplit=0])
|
.. method:: RegexObject.split(string[, maxsplit=0])
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue