I feel pretty good with my regex foo but am running into a difficult one that I could use some help on.
I have a string that needs to be reformatted and it contains functions that can call functions. e.g.
func2(func1(input1, input2), input3)
But it does not matter which order they are called in. So, it could also be
func1(input1, func2(input2, input3))
So, my dilemma is that if I do a regex to find func1 and replace it then I am left with func2 to deal with. The order matters as to the matching of parens. I have not yet figured out how to get a matching () regex to work properly and have read all of the posts here already.
Here is my code to date:
while (<>) { $line = $_; $line =~ s/func1\((.*?)\)/proc1{$1}/g; $line =~ s/func2\((.*?)\)/FUNC $1 END/g; $line =~ s/{/(/g; $line =~ s/}/)/g; print $line; }
The problem is that I get this when I run it I get this:
rather thanproc1(input1, FUNC input2, input3) END FUNC input1, proc1(input2, input3) END
proc1(input1, FUNC input2, input3 END) FUNC input1, proc1(input2, input3) END
Just in case it is not easy to tell the difference I am getting ") END" rather than "END)".
Any help or pointers on this?
In reply to Matching parens on a regex is beating me by bfdi533
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |