I am trying to write a RegEx in .Net to capture the whole function from a list of function that look something like this.
public string Test1()
{
string result = null;
foreach(var item in Entity.EntityProperties)
{
result +=string.Format("inner string with bracket{0}", "test");
}
return result;
}
public string Test5()
{
return string.Format("inner string with bracket{0}", "test");
}
public string Last()
{
return string.Format("inner string with bracket{0}", "test");
}
So I got
((?<function>public string (?<fName>\w+)\(\)\s*{.*?})(?=\s*public string))
this will capture all but the last function... or this
((?<function>public string (?<fName>\w+)\(\)\s*{.*?})(?=\s*(public string)|$))
this will match all function correctly except the first one. The first function only matched partially.
public string Test1()
{
string result = null;
foreach(var item in Entity.EntityProperties)
{
result +=string.Format("inner string with bracket{0}", "test");
} <-- the first capture only get to this point.
Any idea? Please provide some explanation if possible.