This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

classification
Title: re.sub() does not work correctly on '.' pattern and \n
Type: behavior Stage: resolved
Components: Regular Expressions Versions: Python 3.6
process
Status: closed Resolution: not a bug
Dependencies: Superseder:
Assigned To: Nosy List: ezio.melotti, mrabarnett, mrh1997
Priority: normal Keywords:

Created on 2017-07-13 21:27 by mrh1997, last changed 2022-04-11 14:58 by admin. This issue is now closed.

Messages (2)
msg298316 - (view) Author: Robert (mrh1997) * Date: 2017-07-13 21:27
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']
msg298323 - (view) Author: Matthew Barnett (mrabarnett) * (Python triager) Date: 2017-07-13 23:58
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)
'-+-'
History
Date User Action Args
2022-04-11 14:58:49adminsetgithub: 75110
2017-07-13 23:58:25mrabarnettsetstatus: open -> closed
resolution: not a bug
messages: + msg298323

stage: resolved
2017-07-13 21:27:56mrh1997create