[issue45458] "\W" pattern with re.ASCII flag is not equivalent to "[^a-zA-Z0-9_]"

Serhiy Storchaka report at bugs.python.org
Wed Oct 13 05:28:14 EDT 2021


Serhiy Storchaka <storchaka+cpython at gmail.com> added the comment:

It works as expected:

>>> re.sub(r'\W', '', '½ a', 0, re.ASCII)
'a'

You just passed re.ASCII as the count argument, not as the flags argument.

>>> help(re.sub)
Help on function sub in module re:

sub(pattern, repl, string, count=0, flags=0)
    Return the string obtained by replacing the leftmost
    non-overlapping occurrences of the pattern in string by the
    replacement repl.  repl can be either a string or a callable;
    if a string, backslash escapes in it are processed.  If it is
    a callable, it's passed the Match object and must return
    a replacement string to be used.

----------
nosy: +serhiy.storchaka
resolution:  -> not a bug
stage:  -> resolved
status: open -> closed

_______________________________________
Python tracker <report at bugs.python.org>
<https://bugs.python.org/issue45458>
_______________________________________


More information about the Python-bugs-list mailing list