Skip to content

regex bug, incorrectly matching whitespace characters #133727

@cainbit

Description

@cainbit

Bug report

Bug description:

>>> import re
>>> pattern = re.compile(r'^\s+([^"].*)')
>>> print(pattern.match('    hello world'))   # case 1
<re.Match object; span=(0, 15), match='    hello world'>
>>> print(pattern.match('    "hello world"')) # case 2
<re.Match object; span=(0, 17), match='    "hello world"'>

Why case 2 is matched?

CPython versions tested on:

3.13

Operating systems tested on:

Linux

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions