这是我第一次在python中使用正则表达式,我试图弄清楚为什么它认为错误"AttributeError:'str‘object has no attribute 'Match'“
我在Jupyter notebook上这样做。我在这里做错了什么?我只看到了另外一个无用的问题,同样是缺少属性错误。
import re
grp = "Application: Company Name / 184010 - Application Development / 184010 - Contract Express"
rgx = "\w+ *(?!.*-)"
res = grp.match(rgx)
print(res)发布于 2019-04-04 05:18:23
您希望使用re.match,但它从字符串的开头开始。您可以改用findall:
import re
grp = "Application: Company Name / 184010 - Application Development / 184010 - Contract Express"
rgx = "\w+ *(?!.*-)"
res = re.findall(rgx, grp)
print(res) # ['Contract ', 'Express']如果后面也不应该有正斜杠,您可以将其与连字符一起添加到字符类中。
请注意,要与单词后面的空格不匹配,可以在模式中省略后跟asterix *的空格。
\w+(?!.*[-/])https://stackoverflow.com/questions/55498566
复制相似问题