我有一个包含作者和摘要列表的纯文本文件,我试图只提取用于网络分析的作者名称。我的文本遵循这种模式,并包含500+摘要:
2010 - NUCLEAR FORENSICS OF SPECIAL NUCLEAR MATERIAL AT LOS ALAMOS: THREE RECENT STUDIES
Purchase this article
David L. Gallimore, Los Alamos National Laboratory
Katherine Garduno, Los Alamos National Laboratory
Russell C. Keller, Los Alamos National Laboratory
Nuclear forensics of special nuclear materials is a highly specialized field because there are few analytical laboratories in the world that can safely handle nuclear materials, perform high accuracy and precision analysis using validated analytical methods.我在re库中使用Python2.7.6。
我试过了
regex = re.compile(r'( [A-Z][a-z]*,+)')
print regex.findall(text)它只提取姓,加上摘要中逗号之前的大写单词。
使用(r'.*,')可以很好地提取全名,但也可以获取我不需要的整个抽象。
也许regex是错误的方法?任何帮助或想法都会受到欢迎。
发布于 2014-10-04 00:06:20
试试这个
[A-Za-z]* ?([A-Za-z]+.) [A-Za-z]*(?:,+)它使中间名是可选的,加上它将逗号放在一个非捕获组中,从而将逗号从结果中排除在外。
https://stackoverflow.com/questions/26188295
复制相似问题