I've try to parse string like this:
"#1#Process#{some process|info}{some name|some info {child info|child info}}{some name|some info}"
in several messages and create string like this:
#1#Process#
-some process|info
-some name|some info
-child info|child info
-some name|some info
I'm trying to use RegExp and following code:
using System;
using System.Collections;
using System.Text.RegularExpressions;
namespace prRegEXP
{
class Program
{
static String st="";
public static void Main(string[] args)
{
Console.WriteLine("Hello World!");
// TODO: Implement Functionality Here
var pattern = @"\{(.*?)\}";
var query = "#1#Process#{some process|info}{some name|some info {child info|child info}}{some name|some info}";
FindTree (pattern, query);
Console.WriteLine(st);
Console.WriteLine();
Console.WriteLine("Press any key to continue . . . ");
Console.ReadKey(true);
}
private static void FindTree (String pattern, String query) {
var matches = Regex.Matches(query, pattern);
foreach (Match m in matches) {
st += m.Groups[1] + "\n";
if (Regex.IsMatch(m.Groups[1].ToString(), @"\{(.*?)" )) {
FindTree (@"\{(.*?)", m.Groups[1].ToString());
}
}
}
}
}
It's based on example solution I found and I want to create some message tree which take care about messages inside (like child info|child name
). And there can be a lot of them.
I cannot figure out how to match child expressions and send it in recursive parameter. Has any idea or fix?