Skip to content

Commit

Permalink
Make re.sub() and re.split() signature match the current module
Browse files Browse the repository at this point in the history
  • Loading branch information
akuchling committed Aug 10, 2023
1 parent 05555df commit acd1460
Showing 1 changed file with 6 additions and 4 deletions.
10 changes: 6 additions & 4 deletions Doc/howto/regex.rst
Original file line number Diff line number Diff line change
Expand Up @@ -1129,13 +1129,14 @@ whitespace or by a fixed string. As you'd expect, there's a module-level
:func:`re.split` function, too.


.. method:: .split(string [, maxsplit=0])
.. method:: .split(string [, maxsplit=0, flags=0])
:noindex:

Split *string* by the matches of the regular expression. If capturing
parentheses are used in the RE, then their contents will also be returned as
part of the resulting list. If *maxsplit* is nonzero, at most *maxsplit* splits
are performed.
are performed. The *flags* argument is optional and may contain flag values such as
`re.MULTILINE` or `re.VERBOSE`.

You can limit the number of splits made, by passing a value for *maxsplit*.
When *maxsplit* is nonzero, at most *maxsplit* splits will be made, and the
Expand Down Expand Up @@ -1179,7 +1180,7 @@ Another common task is to find all the matches for a pattern, and replace them
with a different string. The :meth:`~re.Pattern.sub` method takes a replacement value,
which can be either a string or a function, and the string to be processed.

.. method:: .sub(replacement, string[, count=0])
.. method:: .sub(replacement, string[, count=0, flags=0])
:noindex:

Returns the string obtained by replacing the leftmost non-overlapping
Expand All @@ -1188,7 +1189,8 @@ which can be either a string or a function, and the string to be processed.

The optional argument *count* is the maximum number of pattern occurrences to be
replaced; *count* must be a non-negative integer. The default value of 0 means
to replace all occurrences.
to replace all occurrences. The *flags* argument is also optional and may contain
flag values such as `re.MULTILINE` or `re.VERBOSE`.

Here's a simple example of using the :meth:`~re.Pattern.sub` method. It replaces colour
names with the word ``colour``::
Expand Down

0 comments on commit acd1460

Please sign in to comment.