程序出错 re.error: look-behind requires fixed-width pattern 代码报出错误
拿 "(?<!pattern)" 这个为例子
(?<!pattern) | 反向否定预查,与正向否定预查类似,只是方向相反。例如" |
re.findall("(?<!95|98|NT|2000)Windows", "1232320Windows")
上面代码执行会报出
re.error: look-behind requires fixed-width pattern
在Python中这个意思就是你需要将你的候选项改为 相同位数才行
re.findall("(?<!95|98|NT|20)Windows", "1232320Windows")
这样写就符合结构 但是缺少关键字
解决方式:
regex · PyPIAlternative regular expression module, to replace re.https://pypi.org/project/regex/
pip install regex
可以通过安装 regex 增强 re 包
import regex as re
print(re.findall("(?<!95|98|NT|2000)Windows", "1232320Windows"))
# 输出
# ['Windows']