Skip to content

re.sub() does not work correctly on '.' pattern and \n #75110

Description

@mrh1997
mannequin
BPO 30927
Nosy @ezio-melotti, @mrh1997

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 2017-07-13.23:58:25.716>
created_at = <Date 2017-07-13.21:27:56.387>
labels = ['expert-regex', 'type-bug', 'invalid']
title = "re.sub() does not work correctly on '.' pattern and \\n"
updated_at = <Date 2017-07-13.23:58:25.715>
user = 'https://github.com/mrh1997'

bugs.python.org fields:

activity = <Date 2017-07-13.23:58:25.715>
actor = 'mrabarnett'
assignee = 'none'
closed = True
closed_date = <Date 2017-07-13.23:58:25.716>
closer = 'mrabarnett'
components = ['Regular Expressions']
creation = <Date 2017-07-13.21:27:56.387>
creator = 'mrh1997'
dependencies = []
files = []
hgrepos = []
issue_num = 30927
keywords = []
message_count = 2.0
messages = ['298316', '298323']
nosy_count = 3.0
nosy_names = ['ezio.melotti', 'mrabarnett', 'mrh1997']
pr_nums = []
priority = 'normal'
resolution = 'not a bug'
stage = 'resolved'
status = 'closed'
superseder = None
type = 'behavior'
url = 'https://bugs.python.org/issue30927'
versions = ['Python 3.6']

Activity

  1. mrh1997 commented on Jul 13, 2017

    mrh1997mannequin
    MannequinAuthor

    When running the command

        re.sub(r'X.', '+', '-X\n-', re.DOTALL)

    you get '-X\n-' instead of '-+-'.

    Curiously findall works correctly:

    re.findall(r'X.', '-X\n-', re.DOTALL) => ['X\n']
    
  2. mrabarnett commented on Jul 13, 2017

    mrabarnettmannequin
    Mannequin

    The 4th parameter is the count, not the flags:

    sub(pattern, repl, string, count=0, flags=0)
    >>> re.sub(r'X.', '+', '-X\n-', flags=re.DOTALL)
    '-+-'
  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

    Labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions