Skip to content

re.sub() bug with IGNORECASE #72038

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
DanWilt mannequin opened this issue Aug 24, 2016 · 3 comments
Closed

re.sub() bug with IGNORECASE #72038

DanWilt mannequin opened this issue Aug 24, 2016 · 3 comments
Labels
topic-regex type-bug An unexpected behavior, bug, or error

Comments

@DanWilt
Copy link
Mannequin

DanWilt mannequin commented Aug 24, 2016

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']

    @DanWilt
    Copy link
    Mannequin Author

    DanWilt mannequin commented Aug 24, 2016

    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.

    @DanWilt DanWilt mannequin added topic-regex type-bug An unexpected behavior, bug, or error labels Aug 24, 2016
    @bitdancer
    Copy link
    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.

    @DanWilt
    Copy link
    Mannequin Author

    DanWilt mannequin commented Aug 24, 2016

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

    On Wed, Aug 24, 2016 at 11:59 AM, R. David Murray <[email protected]>
    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 <[email protected]>
    <https://bugs.python.org/issue27851\>


    Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
    Labels
    topic-regex type-bug An unexpected behavior, bug, or error
    Projects
    None yet
    Development

    No branches or pull requests

    1 participant