Skip to content

Commit 0b5e61d

Browse files
bpo-30397: Add re.Pattern and re.Match. (#1646)
1 parent 8d5a3aa commit 0b5e61d

File tree

13 files changed

+120
-107
lines changed

13 files changed

+120
-107
lines changed

Doc/howto/regex.rst

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -402,7 +402,7 @@ should store the result in a variable for later use. ::
402402

403403
>>> m = p.match('tempo')
404404
>>> m #doctest: +ELLIPSIS
405-
<_sre.SRE_Match object; span=(0, 5), match='tempo'>
405+
<re.Match object; span=(0, 5), match='tempo'>
406406

407407
Now you can query the :ref:`match object <match-objects>` for information
408408
about the matching string. :ref:`match object <match-objects>` instances
@@ -441,7 +441,7 @@ case. ::
441441
>>> print(p.match('::: message'))
442442
None
443443
>>> m = p.search('::: message'); print(m) #doctest: +ELLIPSIS
444-
<_sre.SRE_Match object; span=(4, 11), match='message'>
444+
<re.Match object; span=(4, 11), match='message'>
445445
>>> m.group()
446446
'message'
447447
>>> m.span()
@@ -493,7 +493,7 @@ the RE string added as the first argument, and still return either ``None`` or a
493493
>>> print(re.match(r'From\s+', 'Fromage amk'))
494494
None
495495
>>> re.match(r'From\s+', 'From amk Thu May 14 19:12:10 1998') #doctest: +ELLIPSIS
496-
<_sre.SRE_Match object; span=(0, 5), match='From '>
496+
<re.Match object; span=(0, 5), match='From '>
497497

498498
Under the hood, these functions simply create a pattern object for you
499499
and call the appropriate method on it. They also store the compiled
@@ -685,7 +685,7 @@ given location, they can obviously be matched an infinite number of times.
685685
line, the RE to use is ``^From``. ::
686686

687687
>>> print(re.search('^From', 'From Here to Eternity')) #doctest: +ELLIPSIS
688-
<_sre.SRE_Match object; span=(0, 4), match='From'>
688+
<re.Match object; span=(0, 4), match='From'>
689689
>>> print(re.search('^From', 'Reciting From Memory'))
690690
None
691691

@@ -697,11 +697,11 @@ given location, they can obviously be matched an infinite number of times.
697697
or any location followed by a newline character. ::
698698

699699
>>> print(re.search('}$', '{block}')) #doctest: +ELLIPSIS
700-
<_sre.SRE_Match object; span=(6, 7), match='}'>
700+
<re.Match object; span=(6, 7), match='}'>
701701
>>> print(re.search('}$', '{block} '))
702702
None
703703
>>> print(re.search('}$', '{block}\n')) #doctest: +ELLIPSIS
704-
<_sre.SRE_Match object; span=(6, 7), match='}'>
704+
<re.Match object; span=(6, 7), match='}'>
705705

706706
To match a literal ``'$'``, use ``\$`` or enclose it inside a character class,
707707
as in ``[$]``.
@@ -726,7 +726,7 @@ given location, they can obviously be matched an infinite number of times.
726726

727727
>>> p = re.compile(r'\bclass\b')
728728
>>> print(p.search('no class at all')) #doctest: +ELLIPSIS
729-
<_sre.SRE_Match object; span=(3, 8), match='class'>
729+
<re.Match object; span=(3, 8), match='class'>
730730
>>> print(p.search('the declassified algorithm'))
731731
None
732732
>>> print(p.search('one subclass is'))
@@ -744,7 +744,7 @@ given location, they can obviously be matched an infinite number of times.
744744
>>> print(p.search('no class at all'))
745745
None
746746
>>> print(p.search('\b' + 'class' + '\b')) #doctest: +ELLIPSIS
747-
<_sre.SRE_Match object; span=(0, 7), match='\x08class\x08'>
747+
<re.Match object; span=(0, 7), match='\x08class\x08'>
748748

749749
Second, inside a character class, where there's no use for this assertion,
750750
``\b`` represents the backspace character, for compatibility with Python's

Doc/library/fnmatch.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ patterns.
8686
'(?s:.*\\.txt)\\Z'
8787
>>> reobj = re.compile(regex)
8888
>>> reobj.match('foobar.txt')
89-
<_sre.SRE_Match object; span=(0, 10), match='foobar.txt'>
89+
<re.Match object; span=(0, 10), match='foobar.txt'>
9090

9191

9292
.. seealso::

0 commit comments

Comments
 (0)