I have a string in Python that is comprised of code in C/C++ syntax. I would like to use regular expressions to search through this string and replace an expression of the form 'pow(a,b)' with 'a^b'
I've attempted to do this, but my code does not seem to be working. What would I have to change to be able to replace the expression?
import re def main(): expr = '5*pow(a,b) + 3*pow(b,c) + 3*a + 4*b' print re.sub('pow(.,.)' , '.^.', expr) if __name__ == "__main__": main()
The output of this example program is
5*pow(a,b) + 3*pow(b,c) + 3*a + 4*b
but I would like the output to be
5*a^b + 3*b^c + 3*a + 4*b