【发布时间】:2019-04-04 05:23:56
【问题描述】:
这是我第一次在 python 中使用正则表达式,我试图弄清楚为什么它认为错误“AttributeError: 'str' object has no attribute 'Match'”
我正在 Jupyter 笔记本中执行此操作。我在这里做错了什么?我只看到另一个无用的问题,同样缺少属性错误。
import re
grp = "Application: Company Name / 184010 - Application Development / 184010 - Contract Express"
rgx = "\w+ *(?!.*-)"
res = grp.match(rgx)
print(res)
【问题讨论】:
-
Wrong syntax。
re.match(rgx, grp)或re.compile(rgx).match(grp)。 -
你想在这里匹配什么?
-
最后一个破折号后的所有单词@TimBiegeleisen
-
@meowgoesthedog 谢谢!
-
@TimBiegeleisenweirdly 我没有得到匹配,结果在我使用的正则表达式测试器中还没有匹配。