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