Python 正则表达式相关问题,,这几天学习pytho


这几天学习python,写正则表达式相关代码如下:

import reprint(re.search(r‘(?<=<(\w+)>).*(?=<\/\1>)‘,"<b>ewuiiriur</b>sdksfkj").span())

报错如下:

raise error("look-behind requires fixed-width pattern")
sre_constants.error: look-behind requires fixed-width pattern

在网上找到解决方案,去除了w后面的加号,果然没再报错。同时还有一个意外收获,发现一个python的regex包(链接1,或者,链接2),这个包修正了python自带的re模块的一些bug,很好用。安装办法是:下载-》解压-》将py结尾文件添加到python的Lib目录下。或者,直接看这篇博客。

Python 正则表达式相关问题

评论关闭