Based on tkerwin's answer if you have nested parentheses like in
st = "sum((a+b)/(c+d))"
his answer will not work if you need to take everything between the first opening bracket and the last closing parenthesis to get (a+b)/(c+d) , because it searches for searches on the left of the line and stops in the first closing bracket.
To fix this, you need to use rfind for the second part of the operation, so it will become
st[st.find("(")+1:st.rfind(")")]
FaustoW Nov 25 '16 at 20:37 2016-11-25 20:37
source share