mirror of
https://github.com/python/cpython.git
synced 2025-11-01 18:51:43 +00:00
bpo-32308: Replace empty matches adjacent to a previous non-empty match in re.sub(). (#4846)
This commit is contained in:
parent
0cc99c8cd7
commit
fbb490fd2f
6 changed files with 35 additions and 25 deletions
|
|
@ -1140,12 +1140,12 @@ new string value and the number of replacements that were performed::
|
|||
>>> p.subn('colour', 'no colours at all')
|
||||
('no colours at all', 0)
|
||||
|
||||
Empty matches are replaced only when they're not adjacent to a previous match.
|
||||
Empty matches are replaced only when they're not adjacent to a previous empty match.
|
||||
::
|
||||
|
||||
>>> p = re.compile('x*')
|
||||
>>> p.sub('-', 'abxd')
|
||||
'-a-b-d-'
|
||||
'-a-b--d-'
|
||||
|
||||
If *replacement* is a string, any backslash escapes in it are processed. That
|
||||
is, ``\n`` is converted to a single newline character, ``\r`` is converted to a
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue