模式匹配的最小长度?

时间:2018-11-29 03:02:42

标签: regex python-3.x

开始使用正则表达式。

import re
rx = r"\(.*?\)/DATE"
s = 'THE (HIGH COURT OF HIMACHAL PRADESH)/ORG, (SHIMLA)/PLACE (Criminal\nAppeal No. 235 of 2006)/CASE Judgment Reserved on : (27. 04. 2016)/DATE\nDate of Decision : (June 2, 2016)/DATE")'
print(re.findall(rx, s))

Now the output is 
['(HIGH COURT OF HIMACHAL PRADESH)/ORG, (SHIMLA)/PLACE (Criminal\nAppeal No. 235 of 2006)/CASE', '(27. 04. 2016)/DATE\nDate of Decision : (Criminal\nAppeal No. 235 of 2006)/CASE]

我只想要reduce字符串,而不是从头开始匹配的字符串。

What the output I want?
[(Criminal\nAppeal No. 235 of 2006)/CASE,(Criminal\nAppeal No. 235 of 2006)/CASE]

https://ideone.com/rSRENU

1 个答案:

答案 0 :(得分:0)

您的代码似乎是正确的,也许您应该检查输入错误。

另一种方法是匹配非括号字符[^()]*而不是任何字符.*,例如以下正则表达式:\([^()]*\)/DATE