X Tutup
Skip to content

Commit 090f7be

Browse files
committed
python#16760: use ref:match-objects instead of :class:MatchObject.
1 parent 9f929bb commit 090f7be

File tree

1 file changed

+25
-24
lines changed

1 file changed

+25
-24
lines changed

Doc/howto/regex.rst

Lines changed: 25 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -354,9 +354,9 @@ for a complete listing.
354354
+------------------+-----------------------------------------------+
355355

356356
:meth:`match` and :meth:`search` return ``None`` if no match can be found. If
357-
they're successful, a ``MatchObject`` instance is returned, containing
358-
information about the match: where it starts and ends, the substring it matched,
359-
and more.
357+
they're successful, a :ref:`match object <match-objects>` instance is returned,
358+
containing information about the match: where it starts and ends, the substring
359+
it matched, and more.
360360

361361
You can learn about this by interactively experimenting with the :mod:`re`
362362
module. If you have :mod:`tkinter` available, you may also want to look at
@@ -386,16 +386,16 @@ interpreter to print no output. You can explicitly print the result of
386386
None
387387

388388
Now, let's try it on a string that it should match, such as ``tempo``. In this
389-
case, :meth:`match` will return a :class:`MatchObject`, so you should store the
390-
result in a variable for later use. ::
389+
case, :meth:`match` will return a :ref:`match object <match-objects>`, so you
390+
should store the result in a variable for later use. ::
391391

392392
>>> m = p.match('tempo')
393393
>>> m #doctest: +ELLIPSIS
394394
<_sre.SRE_Match object at 0x...>
395395

396-
Now you can query the :class:`MatchObject` for information about the matching
397-
string. :class:`MatchObject` instances also have several methods and
398-
attributes; the most important ones are:
396+
Now you can query the :ref:`match object <match-objects>` for information
397+
about the matching string. :ref:`match object <match-objects>` instances
398+
also have several methods and attributes; the most important ones are:
399399

400400
+------------------+--------------------------------------------+
401401
| Method/Attribute | Purpose |
@@ -436,8 +436,9 @@ case. ::
436436
>>> m.span()
437437
(4, 11)
438438

439-
In actual programs, the most common style is to store the :class:`MatchObject`
440-
in a variable, and then check if it was ``None``. This usually looks like::
439+
In actual programs, the most common style is to store the
440+
:ref:`match object <match-objects>` in a variable, and then check if it was
441+
``None``. This usually looks like::
441442

442443
p = re.compile( ... )
443444
m = p.match( 'string goes here' )
@@ -454,8 +455,8 @@ Two pattern methods return all of the matches for a pattern.
454455
['12', '11', '10']
455456

456457
:meth:`findall` has to create the entire list before it can be returned as the
457-
result. The :meth:`finditer` method returns a sequence of :class:`MatchObject`
458-
instances as an :term:`iterator`::
458+
result. The :meth:`finditer` method returns a sequence of
459+
:ref:`match object <match-objects>` instances as an :term:`iterator`::
459460

460461
>>> iterator = p.finditer('12 drummers drumming, 11 ... 10 ...')
461462
>>> iterator #doctest: +ELLIPSIS
@@ -476,7 +477,7 @@ You don't have to create a pattern object and call its methods; the
476477
:func:`search`, :func:`findall`, :func:`sub`, and so forth. These functions
477478
take the same arguments as the corresponding pattern method, with
478479
the RE string added as the first argument, and still return either ``None`` or a
479-
:class:`MatchObject` instance. ::
480+
:ref:`match object <match-objects>` instance. ::
480481

481482
>>> print(re.match(r'From\s+', 'Fromage amk'))
482483
None
@@ -786,9 +787,9 @@ Groups indicated with ``'('``, ``')'`` also capture the starting and ending
786787
index of the text that they match; this can be retrieved by passing an argument
787788
to :meth:`group`, :meth:`start`, :meth:`end`, and :meth:`span`. Groups are
788789
numbered starting with 0. Group 0 is always present; it's the whole RE, so
789-
:class:`MatchObject` methods all have group 0 as their default argument. Later
790-
we'll see how to express groups that don't capture the span of text that they
791-
match. ::
790+
:ref:`match object <match-objects>` methods all have group 0 as their default
791+
argument. Later we'll see how to express groups that don't capture the span
792+
of text that they match. ::
792793

793794
>>> p = re.compile('(a)b')
794795
>>> m = p.match('ab')
@@ -908,10 +909,10 @@ numbers, groups can be referenced by a name.
908909
The syntax for a named group is one of the Python-specific extensions:
909910
``(?P<name>...)``. *name* is, obviously, the name of the group. Named groups
910911
also behave exactly like capturing groups, and additionally associate a name
911-
with a group. The :class:`MatchObject` methods that deal with capturing groups
912-
all accept either integers that refer to the group by number or strings that
913-
contain the desired group's name. Named groups are still given numbers, so you
914-
can retrieve information about a group in two ways::
912+
with a group. The :ref:`match object <match-objects>` methods that deal with
913+
capturing groups all accept either integers that refer to the group by number
914+
or strings that contain the desired group's name. Named groups are still
915+
given numbers, so you can retrieve information about a group in two ways::
915916

916917
>>> p = re.compile(r'(?P<word>\b\w+\b)')
917918
>>> m = p.search( '(((( Lots of punctuation )))' )
@@ -1175,11 +1176,11 @@ three variations of the replacement string. ::
11751176

11761177
*replacement* can also be a function, which gives you even more control. If
11771178
*replacement* is a function, the function is called for every non-overlapping
1178-
occurrence of *pattern*. On each call, the function is passed a
1179-
:class:`MatchObject` argument for the match and can use this information to
1180-
compute the desired replacement string and return it.
1179+
occurrence of *pattern*. On each call, the function is passed a
1180+
:ref:`match object <match-objects>` argument for the match and can use this
1181+
information to compute the desired replacement string and return it.
11811182

1182-
In the following example, the replacement function translates decimals into
1183+
In the following example, the replacement function translates decimals into
11831184
hexadecimal::
11841185

11851186
>>> def hexrepl(match):

0 commit comments

Comments
 (0)
X Tutup