I am very curious to know how to easily implement the regular expression balancing group feature used in the following C# code in QM.
--------------------------------------------
public static void Main() {
/*
*multiline comment
*/
string s = """
_Main0
{hello {world {
}
""";//singleline comment
Console.WriteLine(s);
if(1==2){Console.WriteLine(0);/*comment
*/}
//comment
}
--------------------------------------------
The following C# code retrieves the text within the body of the function named Main.
The regular expressions in QM do not support the balancing group feature. So, for the above issue, how can it be resolved without using C# regular expressions?
Thanks for any suggestions and help!
--------------------------------------------
public static void Main() {
/*
*multiline comment
*/
string s = """
_Main0
{hello {world {
}
""";//singleline comment
Console.WriteLine(s);
if(1==2){Console.WriteLine(0);/*comment
*/}
//comment
}
--------------------------------------------
The following C# code retrieves the text within the body of the function named Main.
string s = """"
using System;
public static void Main() {
/*
*multiline comment
*/
string s = """
_Main0
{hello {world {
}
""";//singleline comment
Console.WriteLine(s);
if(1==2){Console.WriteLine(0);/*comment
*/}
//comment
}
public void func(string s1)
{
string s = """
_func0
}hello }world }
""";
Console.WriteLine(s + s1);
}
"""";
var re = """(?s)\bMain(?>\w*)(?>\s*)\((?>[^)]*)\)(?>[^{]*)(?<o>\{)(?<body>(?>/\*.*?\*/|//[^\n]*|"(?>""|\\"|[^"])*"|(?<o>\{)|(?<-o>\})|.)*?)(?<-o>\})(?(o)!)""";
var matches = Regex.Matches(s, re);
foreach (Match m in matches)
{
Console.WriteLine(m.Groups["body"].Value);
}
The regular expressions in QM do not support the balancing group feature. So, for the above issue, how can it be resolved without using C# regular expressions?
Thanks for any suggestions and help!