【发布时间】:2017-04-25 19:33:40
【问题描述】:
我正在尝试从几篇文章中提取城市和国家。我正在使用的正则表达式:
(at [A-Z](?:\w+)?|in [A-Z](?:\w+)?|of [A-Z](?:\w+)?)
它允许我提取这种位置:
of Mogadishu
in Istanbul
of Beletwein
但是,当公式如下时,它不允许我提取位置:
in downtown Tunis
in central Mogadishu
in a town near Mogadishu
我要提取的是在 3 个单词范围内的介词(如 (in,of,through,at) 之后以大写开头的任何单词。
[在链接中有一个文本语料库的样本](https://regex101.com/r/0DRayP/6)和正则表达式
【问题讨论】:
-
正则表达式可能不是执行此操作的方法 - 查看 NLTK。
标签: regex python-3.5