我有一个字符串:
This is @lame在这里,我想提取lame。但这里有个问题,上面的字符串可能是
This is lameThis is @lame but that is @not在这里,我摘录了lame和not
因此,我在每种情况下期望的输出是:
[lame]
[]
[lame,not]如何在python中以健壮的方式提取这些内容?
发布于 2013-05-08 01:46:58
这将给出您请求的输出:
import re
regex = re.compile(r'(?<=@)\w+')
print regex.findall('This is @lame')
print regex.findall('This is lame')
print regex.findall('This is @lame but that is @not')https://stackoverflow.com/questions/16425296
复制相似问题