diff -r 259c82332199 Doc/howto/regex.rst --- a/Doc/howto/regex.rst Sun Nov 17 16:08:23 2013 -0600 +++ b/Doc/howto/regex.rst Mon Nov 18 11:30:52 2013 +0200 @@ -402,7 +402,7 @@ >>> m = p.match('tempo') >>> m #doctest: +ELLIPSIS - <_sre.SRE_Match object at 0x...> + <_sre.SRE_Match object; span=(0, 5), match='tempo'> Now you can query the :ref:`match object ` for information about the matching string. :ref:`match object ` instances @@ -441,7 +441,7 @@ >>> print(p.match('::: message')) None >>> m = p.search('::: message'); print(m) #doctest: +ELLIPSIS - <_sre.SRE_Match object at 0x...> + <_sre.SRE_Match object; span=(4, 11), match='message'> >>> m.group() 'message' >>> m.span() @@ -493,7 +493,7 @@ >>> print(re.match(r'From\s+', 'Fromage amk')) None >>> re.match(r'From\s+', 'From amk Thu May 14 19:12:10 1998') #doctest: +ELLIPSIS - <_sre.SRE_Match object at 0x...> + <_sre.SRE_Match object; span=(0, 5), match='From '> Under the hood, these functions simply create a pattern object for you and call the appropriate method on it. They also store the compiled @@ -685,7 +685,7 @@ line, the RE to use is ``^From``. :: >>> print(re.search('^From', 'From Here to Eternity')) #doctest: +ELLIPSIS - <_sre.SRE_Match object at 0x...> + <_sre.SRE_Match object; span=(0, 4), match='From'> >>> print(re.search('^From', 'Reciting From Memory')) None @@ -697,11 +697,11 @@ or any location followed by a newline character. :: >>> print(re.search('}$', '{block}')) #doctest: +ELLIPSIS - <_sre.SRE_Match object at 0x...> + <_sre.SRE_Match object; span=(6, 7), match='}'> >>> print(re.search('}$', '{block} ')) None >>> print(re.search('}$', '{block}\n')) #doctest: +ELLIPSIS - <_sre.SRE_Match object at 0x...> + <_sre.SRE_Match object; span=(6, 7), match='}'> To match a literal ``'$'``, use ``\$`` or enclose it inside a character class, as in ``[$]``. @@ -726,7 +726,7 @@ >>> p = re.compile(r'\bclass\b') >>> print(p.search('no class at all')) #doctest: +ELLIPSIS - <_sre.SRE_Match object at 0x...> + <_sre.SRE_Match object; span=(3, 8), match='class'> >>> print(p.search('the declassified algorithm')) None >>> print(p.search('one subclass is')) @@ -744,7 +744,7 @@ >>> print(p.search('no class at all')) None >>> print(p.search('\b' + 'class' + '\b')) #doctest: +ELLIPSIS - <_sre.SRE_Match object at 0x...> + <_sre.SRE_Match object; span=(0, 7), match='\x08class\x08'> Second, inside a character class, where there's no use for this assertion, ``\b`` represents the backspace character, for compatibility with Python's diff -r 259c82332199 Doc/library/fnmatch.rst --- a/Doc/library/fnmatch.rst Sun Nov 17 16:08:23 2013 -0600 +++ b/Doc/library/fnmatch.rst Mon Nov 18 11:30:52 2013 +0200 @@ -86,7 +86,7 @@ '.*\\.txt$' >>> reobj = re.compile(regex) >>> reobj.match('foobar.txt') - <_sre.SRE_Match object at 0x...> + <_sre.SRE_Match object; span=(0, 10), match='foobar.txt'> .. seealso:: diff -r 259c82332199 Doc/library/re.rst --- a/Doc/library/re.rst Sun Nov 17 16:08:23 2013 -0600 +++ b/Doc/library/re.rst Mon Nov 18 11:30:52 2013 +0200 @@ -755,7 +755,7 @@ >>> 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 @@ >>> 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 @@ >>> 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 @@ >>> 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 @@ >>> 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 @@ 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 @@ 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