以下代码在python中不起作用,但在测试应用程序(如Jedit的插件“正则表达式测试器”)中起作用:
import re
m = "text0 { \int_{0}^{1} f(s) \ds text } text2 {foo-abs2} text4 "
s = re.compile(r'\{[^{}]*(\{[^{}]*\}[^{}]*)*\}')
t = s.findall(m)
print(t) # gives ['{1} f(s) \\ds text ', '']
"""
Should gives back
{ \int_{0}^{1} f(s) \ds text }
{foo-abs2}
"""
怎么了?