I have a method like signature that looks like this:
void methodName(str arg1, int arg2, int arg3 = 4)
{
}
or
str methodName2(int arg1)
{
}
I want to extract only the parameters of this to give
(str arg1, int arg2, int arg3 = 4)
(int arg1)
Here is what I have tried. This never matches for me.
string namePortion = String.Format(@"^.*{0}", "methodName");
Regex rex = new Regex(namePortion + @"\s*(?<params>\(.*\)).*\{", RegexOptions.Compiled | RegexOptions.Multiline);
string parms = "";
Match m = rex.Match(sourceCode);
if (m.Success)
{
parms = m.Groups["params"].Value;
}
I have also tested this out in RegexBuddy, and it seems to work, so I am not sure what is wrong.
If you’re going VERY broad, the following should work for you:
To just grab prototypes (and use brace as a delimiter):
If you’re looking for something more specific, let me know.
EDIT Added
(?:^|[\r\n])which makes sure it’s at the start of the file or line.