summaryrefslogtreecommitdiffstats
path: root/Doc/library/re.rst
diff options
context:
space:
mode:
authorEzio Melotti <ezio.melotti@gmail.com>2013-11-23 18:27:27 (GMT)
committerEzio Melotti <ezio.melotti@gmail.com>2013-11-23 18:27:27 (GMT)
commit7571941db6591c7521311274f0ea3c83657eb911 (patch)
treebfbddf4abe687d23a2ddba97fd65ec5acd13e0cd /Doc/library/re.rst
parent7cd9fbe08743a96ce3cccebf1ac3c4a4f6f74e71 (diff)
downloadcpython-7571941db6591c7521311274f0ea3c83657eb911.zip
cpython-7571941db6591c7521311274f0ea3c83657eb911.tar.gz
cpython-7571941db6591c7521311274f0ea3c83657eb911.tar.bz2
#19639: update the repr of the match objects in the docs. Patch by Claudiu Popa.
Diffstat (limited to 'Doc/library/re.rst')
-rw-r--r--Doc/library/re.rst18
1 files changed, 9 insertions, 9 deletions
diff --git a/Doc/library/re.rst b/Doc/library/re.rst
index 762ca49..220ce86 100644
--- a/Doc/library/re.rst
+++ b/Doc/library/re.rst
@@ -755,7 +755,7 @@ attributes:
>>> pattern = re.compile("d")
>>> pattern.search("dog") # Match at index 0
- <_sre.SRE_Match object at ...>
+ <_sre.SRE_Match object; span=(0, 1), match='d'>
>>> pattern.search("dog", 1) # No match; search doesn't include the "d"
@@ -772,7 +772,7 @@ attributes:
>>> 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 ...>
+ <_sre.SRE_Match object; span=(1, 2), match='o'>
If you want to locate a match anywhere in *string*, use
:meth:`~regex.search` instead (see also :ref:`search-vs-match`).
@@ -1139,7 +1139,7 @@ For example::
>>> re.match("c", "abcdef") # No match
>>> re.search("c", "abcdef") # Match
- <_sre.SRE_Match object at ...>
+ <_sre.SRE_Match object; span=(2, 3), match='c'>
Regular expressions beginning with ``'^'`` can be used with :func:`search` to
restrict the match at the beginning of the string::
@@ -1147,7 +1147,7 @@ restrict the match at the beginning of the string::
>>> re.match("c", "abcdef") # No match
>>> re.search("^c", "abcdef") # No match
>>> re.search("^a", "abcdef") # Match
- <_sre.SRE_Match object at ...>
+ <_sre.SRE_Match object; span=(0, 1), match='a'>
Note however that in :const:`MULTILINE` mode :func:`match` only matches at the
beginning of the string, whereas using :func:`search` with a regular expression
@@ -1155,7 +1155,7 @@ beginning with ``'^'`` will match at the beginning of each line.
>>> re.match('X', 'A\nB\nX', re.MULTILINE) # No match
>>> re.search('^X', 'A\nB\nX', re.MULTILINE) # Match
- <_sre.SRE_Match object at ...>
+ <_sre.SRE_Match object; span=(4, 5), match='X'>
Making a Phonebook
@@ -1274,9 +1274,9 @@ another one to escape it. For example, the two following lines of code are
functionally identical:
>>> re.match(r"\W(.)\1\W", " ff ")
- <_sre.SRE_Match object at ...>
+ <_sre.SRE_Match object; span=(0, 4), match=' ff '>
>>> re.match("\\W(.)\\1\\W", " ff ")
- <_sre.SRE_Match object at ...>
+ <_sre.SRE_Match object; span=(0, 4), match=' ff '>
When one wants to match a literal backslash, it must be escaped in the regular
expression. With raw string notation, this means ``r"\\"``. Without raw string
@@ -1284,9 +1284,9 @@ notation, one must use ``"\\\\"``, making the following lines of code
functionally identical:
>>> re.match(r"\\", r"\\")
- <_sre.SRE_Match object at ...>
+ <_sre.SRE_Match object; span=(0, 1), match='\\'>
>>> re.match("\\\\", r"\\")
- <_sre.SRE_Match object at ...>
+ <_sre.SRE_Match object; span=(0, 1), match='\\'>
Writing a Tokenizer