bpo-30397: Add re.Pattern and re.Match. (#1646) · python/cpython@0b5e61d (original) (raw)
`@@ -402,7 +402,7 @@ should store the result in a variable for later use. ::
`
402
402
``
403
403
` >>> m = p.match('tempo')
`
404
404
` >>> m #doctest: +ELLIPSIS
`
405
``
`-
<_sre.SRE_Match object; span=(0, 5), match='tempo'>
`
``
405
`+
<re.Match object; span=(0, 5), match='tempo'>
`
406
406
``
407
407
`` Now you can query the :ref:match object <match-objects>
for information
``
408
408
`` about the matching string. :ref:match object <match-objects>
instances
``
`@@ -441,7 +441,7 @@ case. ::
`
441
441
` >>> print(p.match('::: message'))
`
442
442
` None
`
443
443
` >>> 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'>
`
445
445
` >>> m.group()
`
446
446
` 'message'
`
447
447
` >>> m.span()
`
``` @@ -493,7 +493,7 @@ the RE string added as the first argument, and still return either None
or a
`493`
`493`
` >>> print(re.match(r'From\s+', 'Fromage amk'))
`
`494`
`494`
` None
`
`495`
`495`
` >>> 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 '>
`
`497`
`497`
``
`498`
`498`
`Under the hood, these functions simply create a pattern object for you
`
`499`
`499`
`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.
`
`685`
`685`
``` line, the RE to use is ``^From``. ::
686
686
``
687
687
` >>> 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'>
`
689
689
` >>> print(re.search('^From', 'Reciting From Memory'))
`
690
690
` None
`
691
691
``
`@@ -697,11 +697,11 @@ given location, they can obviously be matched an infinite number of times.
`
697
697
` or any location followed by a newline character. ::
`
698
698
``
699
699
` >>> print(re.search('}$', '{block}')) #doctest: +ELLIPSIS
`
700
``
`-
<_sre.SRE_Match object; span=(6, 7), match='}'>
`
``
700
`+
<re.Match object; span=(6, 7), match='}'>
`
701
701
` >>> print(re.search('}$', '{block} '))
`
702
702
` None
`
703
703
` >>> print(re.search('}$', '{block}\n')) #doctest: +ELLIPSIS
`
704
``
`-
<_sre.SRE_Match object; span=(6, 7), match='}'>
`
``
704
`+
<re.Match object; span=(6, 7), match='}'>
`
705
705
``
706
706
``` To match a literal '$'
, use \$
or enclose it inside a character class,
`707`
`707`
``` as in ``[$]``.
`@@ -726,7 +726,7 @@ given location, they can obviously be matched an infinite number of times.
`
726
726
``
727
727
` >>> p = re.compile(r'\bclass\b')
`
728
728
` >>> 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'>
`
730
730
` >>> print(p.search('the declassified algorithm'))
`
731
731
` None
`
732
732
` >>> print(p.search('one subclass is'))
`
`@@ -744,7 +744,7 @@ given location, they can obviously be matched an infinite number of times.
`
744
744
` >>> print(p.search('no class at all'))
`
745
745
` None
`
746
746
` >>> 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'>
`
748
748
``
749
749
` Second, inside a character class, where there's no use for this assertion,
`
750
750
``` \b
represents the backspace character, for compatibility with Python's
```