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

Owen report at bugs.python.org
Wed Oct 13 05:10:37 EDT 2021


New submission from Owen <owentrigueros at gmail.com>:

"\W" regex pattern, when used with `re.ASCII`, is expected to have the same behavior as "[^a-zA-Z0-9_]" (see [1]).

For example, the following `sub()` call

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

should return the same as this one:

```
>>> re.sub('[^a-zA-Z0-9_]', '', '½ a', re.ASCII)
'a'
```

But it does not.

[1] https://docs.python.org/3/library/re.html#regular-expression-syntax

----------
components: Regular Expressions
messages: 403810
nosy: ezio.melotti, mrabarnett, owentrigueros
priority: normal
severity: normal
status: open
title: "\W" pattern with re.ASCII flag is not equivalent to "[^a-zA-Z0-9_]"
type: behavior
versions: Python 3.10, Python 3.6, Python 3.7, Python 3.8, Python 3.9

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


More information about the New-bugs-announce mailing list