学习正则表达式反向引用,我不明白发生了什么

Learning Regex Backreferencing, and I don't understand what's going on

str2=re.match("\W(.)\W", " f\x01 ")
print(str2)

OUPUT: <re.Match object; span=(0, 4), match=' f\x01 '>

当我将输入字符串中的 'x' 更改为 'y' 或任何其他字母并且将 returns NONE 更改为 str2=re.match("\W(.)\W", " f\y01 ")

str2=re.match("\W(.)\W", " ff ")
print(str2)

OUTPUT: None

因此,由于这些代码段之间唯一发生变化的是输入的字符串以与 RE 进行比较。据我了解,RE 的意思是: [^a-zA-Z0-9_] + 任意字符 + [^a-zA-Z0-9_],所以我不明白为什么这些模式不能同时匹配 RE。

如果这可能会以某种方式影响它,我正在使用 Jupyter Notebook。如果这是我忽略的非常明显/业余的东西,我很抱歉,谢谢。

没关系,就是少了r:

import re

str2=re.match(r"\W(.)\W", " ff ")
print(str2)

If you wish to explore/simplify/modify the expression, it's been explained on the top right panel of regex101.com. If you'd like, you can also watch in this link, how it would match against some sample inputs.