Python正则表达式在破折号之间找到alpha字符串

时间:2015-03-14 21:15:13

标签: python regex

我有一系列字符串,看起来大致如此。

- Conf. w/attorney, defendant, bondsman. Magistrate ct., PA - Research - 2.7 hrs - 86 miles

我需要编写一个与

匹配的正则表达式

- Conf. w/attorney, defendant, bondsman. Magistrate ct., PA -

- Research -部分字符串。

但不是hrsmiles段。

x = re.findall('-[.^\-0-9]*-', line)

到目前为止我已尝试过,但这并没有返回任何匹配项。

我确定我只是写错了RE。

1 个答案:

答案 0 :(得分:1)

如果您想使用Regex进行操作,可以尝试:

r'.*?(?= \d)'

检查:https://regex101.com/r/uG0fI2/3