RE replace problem too

O

oyster

in my case, I want to replace all the function name with '', that is
sin(1) -> (1)
sin(pi*(2+4)) -> (pi*(2+4))
how can I use RE in this situation? thanx
 
L

Lie Ryan

oyster said:
in my case, I want to replace all the function name with '', that is
sin(1) -> (1)
sin(pi*(2+4)) -> (pi*(2+4))
how can I use RE in this situation? thanx

this works if there is no implicit multiplication:

re.sub('\w+\(', '(', 'sin(pi*(2+4))')

this one might be more robust:
re.sub('[a-zA-Z]\w*\s*\(', '(', 'sin(pi*cos(2+4))')
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads


Members online

Forum statistics

Threads
473,780
Messages
2,569,607
Members
45,240
Latest member
pashute

Latest Threads

Top