Skip to content

Multiline re.sub stops replacing before the end of the input #96938

Closed as not planned
@igfoo

Description

@igfoo

Bug report

With:

#!/usr/bin/python

import re

text = "'x' " * 12
print(text)
print(re.sub("'([^' ]+)'", r'\1', text))
print(re.sub("'([^' ]+)'", r'\1', text, re.MULTILINE))

I get

'x' 'x' 'x' 'x' 'x' 'x' 'x' 'x' 'x' 'x' 'x' 'x' 
x x x x x x x x x x x x 
x x x x x x x x 'x' 'x' 'x' 'x' 

but I would expect

'x' 'x' 'x' 'x' 'x' 'x' 'x' 'x' 'x' 'x' 'x' 'x' 
x x x x x x x x x x x x 
x x x x x x x x x x x x 

with both 3.9.2 and 3.10.7 on Debian Linux, x86_64.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions