【发布时间】:2013-09-16 18:05:03
【问题描述】:
我已经编写了这个正则表达式,但它没有按预期工作。
((?:[A-Z][\w]+)?),[\s]([A-Z]{2})
以下是示例输入。
Fort Worth, TX
This is Forth Worth, TX
We are looking for someone from Columbus, MS.
我希望在 python 中使用正则表达式的上述字符串样本中包含 City 和 State ,但这只是没有按预期工作。
print re.findall('((?:[A-Z][\w]+){1,2}),[\s]([A-Z]{2})', input)
我错过了什么?
【问题讨论】:
-
城市名称之间的空格。
-
您可能想要使用某种自然语言解析。