【发布时间】:2019-02-18 04:27:39
【问题描述】:
我需要过滤句子,从整个句子中只选择几个词
例如,我有示例文本:
ID: a9000006
NSF Org : DMI
Total Amt. : $225024
Abstract :This SBIR proposal is aimed at (1) the synthesis of new ferroelectric liquid crystals with ultra-high polarization,
chemical stability and low viscosity
token = re.compile('a90[0-9][0-9][0-9][0-9][0-9]| [$][\d]+ |')
re.findall(token, filetext)
我得到'a9000006','$225024',但我不知道如何为"NSF Org:" 之后的三个大写字母编写正则表达式,即"DMI" 和"Abstract:" 之后的所有文本
【问题讨论】:
-
[^:]+将抓取所有非冒号。 -
带限制的简单拆分将比正则表达式高效得多。