Skip to content

re.sub replaces only first 32 matches with re.U flag #55471

Closed

Description

@EugeneMorozov
BPO 11262

Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.

Show more details

GitHub fields:

assignee = None
closed_at = <Date 2011-02-20.23:01:03.740>
created_at = <Date 2011-02-20.22:28:09.731>
labels = ['type-security', 'expert-regex', 'invalid']
title = 're.sub replaces only first 32 matches with re.U flag'
updated_at = <Date 2011-02-20.23:01:03.731>
user = 'https://bugs.python.org/EugeneMorozov'

bugs.python.org fields:

activity = <Date 2011-02-20.23:01:03.731>
actor = 'SilentGhost'
assignee = 'none'
closed = True
closed_date = <Date 2011-02-20.23:01:03.740>
closer = 'SilentGhost'
components = ['Regular Expressions']
creation = <Date 2011-02-20.22:28:09.731>
creator = 'Eugene.Morozov'
dependencies = []
files = []
hgrepos = []
issue_num = 11262
keywords = []
message_count = 2.0
messages = ['128923', '128925']
nosy_count = 2.0
nosy_names = ['SilentGhost', 'Eugene.Morozov']
pr_nums = []
priority = 'normal'
resolution = 'not a bug'
stage = None
status = 'closed'
superseder = None
type = 'security'
url = 'https://bugs.python.org/issue11262'
versions = ['Python 2.6']

Activity

  1. EugeneMorozov commented on Feb 20, 2011

    EugeneMorozovmannequin
    MannequinAuthor
    There's a peculiar and difficult to find bug in the re.sub method. Try following example:
    >>> text = 'X'*4096
    >>> nt = re.sub(u"XX", u".", text, re.U)
    >>> nt
    u'............XXXXXXXXXXXXXXXXXXX' (only 32 dots, the rest of the string is not changed).

    If I first compile regexp, and then perform compiled_regexp.sub, everything seems to work correctly.

  2. SilentGhost commented on Feb 20, 2011

    SilentGhostmannequin
    Mannequin

    If you read docs carefully, you notice that re.sub doesn't accept flags argument. Its 4th argument is count, re.U numerical value is 32.

    Closing as invalid. There are some duplicates too, I'm sure.

  3. transferred this issue fromon Apr 10, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions