changing ** operator to power function using parsing?
My requirement is to change ** operator to power function For example 1.Input -"B**2" Output - power(B,2) 2."B**2&&T**2*X" Output - power(B,2) I have wrote following regular expression to address that problem rx=r"([a-zA-Z0-9]+)\*\*([a-zA-Z0-9()]+)" result = regex.sub(rx, r"power(\1,\2)", expression, 0, regex.IGNORECASE | regex.MULTILINE) But above code successfully converting expression similar to the example 1 and example 2, but failed to convert expression like (a+1)**2 or ((a+b)*c)**2 . I realized regular expression is not the best way to handle such scenarios. Instead of that parsing will