Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Implementing a feature similar to C# regular expression balancing groups in QM
#1
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.
 
Code:
Copy      Help
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?  Huh
Thanks for any suggestions and help!


Messages In This Thread
Implementing a feature similar to C# regular expression balancing groups in QM - by Davider - 10-06-2024, 01:24 PM

Forum Jump:


Users browsing this thread: 1 Guest(s)