我有一根这样的绳子
text1="sedentary. Allan Takocok. That's the conclusion of two studies published in this week's issue of The New England Journal of Medicine."
我想在这篇课文中提取以大写字母开头但不跟句号的单词。所以[塔科克新英格兰医学杂志]应该在没有[那是艾伦]的情况下提取。你知道吗
我试过这个正则表达式,但仍然提取艾伦和那
t=re.findall("((?:[A-Z]\w+[ -]?)+)",text1)
下面是一个使用
re.findall
的选项:这张照片:
下面是正则表达式模式的解释:
在这种情况下,可能会找到一个正则表达式,但它往往会变得混乱。你知道吗
相反,我建议分两步进行:
这种令牌拆分已经足够复杂了。你知道吗
使用这个标记列表,可以更容易地表达实际需求,因为您现在使用的是定义良好的标记,而不是任意字符序列。你知道吗
我在令牌列表中保留了空格,因为您可能想区分“a”。品牌名称'或'www.example.org“还有句末的点。你知道吗
使用这个标记列表,比以前更容易表达规则,比如“必须在前面加一个点”。你知道吗
我希望你的规则随着时间的推移变得相当复杂,因为你处理的是自然语言文本。因此,对令牌的抽象。你知道吗
这应该是你要找的正则表达式:
在这里查看regex101:https://regex101.com/r/EoPqgw/1
相关问题 更多 >
编程相关推荐