Skip to content

re.sub() bug with IGNORECASE #72038

Closed
Closed

Description

@DanWilt
mannequin
BPO 27851
Nosy @ezio-melotti, @bitdancer
Files
  • re_bug.py: MWE for re bug
  • 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 2016-08-24.15:59:54.318>
    created_at = <Date 2016-08-24.15:57:11.028>
    labels = ['expert-regex', 'type-bug', 'invalid']
    title = 're.sub() bug with IGNORECASE'
    updated_at = <Date 2016-08-24.18:28:02.106>
    user = 'https://bugs.python.org/DanWilt'

    bugs.python.org fields:

    activity = <Date 2016-08-24.18:28:02.106>
    actor = 'Dan Wilt'
    assignee = 'none'
    closed = True
    closed_date = <Date 2016-08-24.15:59:54.318>
    closer = 'r.david.murray'
    components = ['Regular Expressions']
    creation = <Date 2016-08-24.15:57:11.028>
    creator = 'Dan Wilt'
    dependencies = []
    files = ['44212']
    hgrepos = []
    issue_num = 27851
    keywords = []
    message_count = 3.0
    messages = ['273575', '273576', '273584']
    nosy_count = 4.0
    nosy_names = ['ezio.melotti', 'mrabarnett', 'r.david.murray', 'Dan Wilt']
    pr_nums = []
    priority = 'normal'
    resolution = 'not a bug'
    stage = 'resolved'
    status = 'closed'
    superseder = None
    type = 'behavior'
    url = 'https://bugs.python.org/issue27851'
    versions = ['Python 2.7', 'Python 3.5']

    Activity

    1. DanWilt commented on Aug 24, 2016

      DanWiltmannequin
      MannequinAuthor

      Working with re.sub() noted strange behavior with re.I set, seems like a bug. Noted in both Python 2.7.12 and Python 3.5.2, Anaconda custom build (32-bit) on Windows 7.

      >>> import re
      >>> re.sub('\.', '', '.....')
      ''
      >>> re.sub('\.', '', '.....', re.I)
      '...'
      >>> re.sub('\.', '', '.....', re.L)
      '.'

      The first case is the expected behavior, the second and third aren't. Oddly enough,

      >>> re.sub('\.', '', '.....', re.L | re.I)
      ''

      MWE file attached (python3)

      Thanks, I'm a heavy python user, but not all that advanced - hope this is helpful and I'm not just being stupid.

    2. bitdancer commented on Aug 24, 2016

      @bitdancer
      Member

      I really wish we could "fix" this somehow, since we get an issue opened for it probably every two or three months.

      The fourth argument to re.sub is the count, not the flags.

    3. DanWilt commented on Aug 24, 2016

      DanWiltmannequin
      MannequinAuthor

      Thanks! That helps. I apologize for raising a non-existent issue.
      Dan

      On Wed, Aug 24, 2016 at 11:59 AM, R. David Murray <report@bugs.python.org>
      wrote:

      R. David Murray added the comment:

      I really wish we could "fix" this somehow, since we get an issue opened
      for it probably every two or three months.

      The fourth argument to re.sub is the count, not the flags.

      ----------
      nosy: +r.david.murray
      resolution: -> not a bug
      stage: -> resolved
      status: open -> closed


      Python tracker <report@bugs.python.org>
      <https://bugs.python.org/issue27851\>


    4. 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

      Labels

      Projects

      No projects

        Milestone

        No milestone

        Relationships

        None yet

        Development

        No branches or pull requests

        Issue actions