0
我想我可能已经发现了Python的正则表达式的错误,或者我犯了一个错误?Python正则表达式匹配对象属性错误?
import regex
...
iters = regex.finditer("Teams? [^u]*? rejected",file)
for Result in iters:
Beginning = Result.span()[0]
End = Result.span()[1]
Text = Result.match()
运行上面的代码给出了以下结果/错误。它清楚地输出带匹配属性的regex.Match对象,然后给出该对象没有属性匹配的错误。
<regex.Match object; span=(7684, 7708), match='Teams 1, 2 and 7 are rejected'>
Traceback (most recent call last):
File "b.py", line 72, in <module>
Text = Result.match()
AttributeError: '_regex.Match' object has no attribute 'match'
我写了这个代码前一段时间在不同的计算机上,它的工作。现在在我的新电脑上出现这个错误。不知道我的以前版本的正则表达式是什么,这是我目前的版本。
>>pip show regex
Name: regex
Version: 2017.2.8
Summary: Alternative regular expression module, to replace re.
Home-page: https://bitbucket.org/mrabarnett/mrab-regex
Author: Matthew Barnett
Author-email: [email protected]
License: Python Software Foundation License
99.9%的时间,如果你想知道它是流行软件中的错误还是你犯了错误,那就是后者。 – Barmar
我只是说,因为代码在以前的版本上工作得很好,现在它没有。 – projectgonewrong
标准Python正则表达式模块的名称是're',而不是'regex'。 – Barmar