Match:
function (.+{.*(.*{(?2)}.*)*.*?})
with the multiline parameter on
Then replace with:
private \1
This RegEx matches the function entirely, including any nested functions/if statements etc, so you can replace only the outermost one.
Explanation
function Matches function keyword
( Starts capture group
.+ Matches function name and parameters
{ Opens function
.* Matches any code in function
( Starts new capture group (2) for catching internal curly braces
.* Matches any code in function
{ Matches opening curly brace
(?2) Matches capture group (2), to match any code and curly braces inside
} Matches closing curly brace
.* Matches any code
)* Closes capture group (2) and allows it to be repeated
.*? Matches any code, until next curly brace
} Matches closing curly brace
) Closes capture group
Note that the recursion ((?2)
) is not supported in .net by default, so you'll have to use another RegEx-Engine for C#, such as PCRE for .Net.
If you don't want to use another engine, you can replace the (?2)
with (.*{(?2)}.*)*
recursively as deep as you want, as to match nested if loops etc., and finally replace the (?2)
with .*
.
The result should look something like this:
function (.+{.*(.*{(.*{(.*{(.*{(.*{(.*{(.*)}.*)*}.*)*}.*)*}.*)*}.*)*}.*)*.*?})