using System;
using System.Text.RegularExpressions;
public class Example
{
public static void Main()
{
string pattern = @"\w+\([^()]*(((?'parenthesesPair'\()[^()]*)+((?'-parenthesesPair'\))[^()]*)+)*(?(parenthesesPair)(?!))\)";
string input = @"(PROT(MONITOR)TYPE(LCD)MODEL(MSTAR)CMDS(01 02 03 07 0C E3 F3)VCP(02 04 05 08 0B 0C 10 12 14(01(?(((i)))) 04 05 06 07 08 0A 0B) 16 18 1A 52 54(00 01) 60(00 11 12 0F 10 21 22 2F 30 31) 62 6C 6E 70 72(05 78 FB 50 64 78 8C A0) 86(01 02 08) 8D(01 02) A4 A5 AA(01 02) AC AE B6 C0 C6 C8 C9 CA(01 02) CC(02 03 04 05 07 08 09 0A 0C 0D 01 06 0B 0E 12 14 16 17 1A 1E 24) D6(01 04 05) DC(0E 00 01 02 03 05 08 0B 1F E1) DF E0(00 01 02 03 04) E9(00 02) EB(00 01 02 03) EC(00 01() 02 03) F0(00 01) F2(00 01 02 03 04) F6(01 ) F7(42 FF) F9(00 01 02 03 04) FF)MSWHQL(1)ASSET_EEP(40)MCCS_VER(2.2))";
RegexOptions options = RegexOptions.Multiline;
foreach (Match m in Regex.Matches(input, pattern, options))
{
Console.WriteLine("'{0}' found at index {1}.", m.Value, m.Index);
}
}
}
Please keep in mind that these code samples are automatically generated and are not guaranteed to work. If you find any syntax errors, feel free to submit a bug report. For a full regex reference for C#, please visit: https://msdn.microsoft.com/en-us/library/system.text.regularexpressions.regex(v=vs.110).aspx