【发布时间】:2016-08-30 11:35:38
【问题描述】:
我正在尝试将以下匹配正则表达式的输出作为
所有部门,例如。 ['Sector-34, Noida', 'Sec 434 Gurgaon', 'sec100']
P.S - sec47,\n gurgaon 是特例
但我怀疑输出很奇怪,因为 [('', 'tor')]
import re
string = "Sector-34, Noida is found to be awesome place I went to eat burgers there and Sec 434 Gurgoan is also good sec100 is one the finest places for outing."
match = re.findall(r"Sec(tor)?-?\d+\s+?\w+|Sec(tor)?\s+?\d+", string, re.IGNORECASE)
print match
谢谢,提前!
【问题讨论】:
-
您确定需要
sec100而不是sec100 is? -
@WiktorStribiżew。感谢回复!是的,我也想要 sec100
-
我的意思是,你怎么知道什么时候匹配数字后面的单词字符,什么时候不匹配?
Sec 434 Gurgaon和sec100之间的规则区别是什么?没有空间?看看我的意思 -Sec(?:tor)?-?\s*\d+\W+?\w+. -
@WiktorStribiżew Yaa。我知道了。谢谢!
标签: python regex python-2.7