これは、バランスの取れたグループを使用して、それを行う必要があります。必要に応じてスイッチ/ケースを変更してください。
class TnsRegex {public void Test(){Regex reTns =new Regex(_pattern、RegexOptions.Singleline | RegexOptions.IgnorePatternWhitespace); MatchCollection matchCollection =reTns.Matches(_text); foreach(matchCollectionでの一致一致){foreach(match.Groups ["Settings"]。Capturesでのキャプチャキャプチャ){string []設定=capture.Value.Split(new [] {'='}、StringSplitOptions.RemoveEmptyEntries);文字列キー=設定[0].Trim(); string val =settings [1] .Trim(); if(val.Contains( "("))continue; switch(key){case "HOST":break; case "PORT":break; case "SERVICE_NAME":break; case "SERVER":break;} Console.WriteLine (key + ":" + val);}}} string _pattern =@ "MYSCHEMA \ s + =\ s + \([^ \(\)] *(((? \()[^ \(\) ] *)+((?<設定-開く> \))[^ \(\)] *)+)*(?(開く)(?!))\) "; string _text =@" MYSCHEMA =(DESCRIPTION =(ADDRESS =(PROTOCOL =TCP)(HOST =MYHOST)(PORT =1234))(CONNECT_DATA =(SERVER =DEDICATED)(SERVICE_NAME =MYSERVICE.LOCAL)))SOMESCHEMA =(DESCRIPTION =(ADDRESS_LIST =(ADDRESS =(PROTOCOL =TCP)(HOST =REMOTEHOST)(PORT =1234)))(CONNECT_DATA =(SERVICE_NAME =REMOTE))) ";} コード> プレ>