跳到内容

unraw-re-pattern (RUF039)

有时提供修复。

此规则不稳定且处于预览状态。使用需要 --preview 标志。

作用

reregex 调用的第一个参数不是原始字符串时,报告以下情况

  • 对于 regexrecompilefindallfinditerfullmatchmatchsearchsplitsubsubn
  • regex 特有:splititersubfsubfntemplate

为什么这不好?

正则表达式应该使用原始字符串编写,以避免双重转义。

示例

re.compile("foo\\bar")

建议改为

re.compile(r"foo\bar")