正则表达式取括号内的值 按第一个空格分割字符串

时间:2022-11-20 18:49:45
<pre name="code" class="csharp">        Regex reg = new Regex(@"\((.*)\)");
        string a = "张三(Zhang san)";
        Match m = reg.Match(a);

        string yingwenname = m.Groups[1].Value;
        string f = yingwenname.Substring(0, yingwenname.IndexOf(" ") - 1);//名字,首
        string l = yingwenname.Substring(yingwenname.IndexOf(" ") + 1, yingwenname.Length - yingwenname.IndexOf(" ") - 1);//名字结尾

m.Groups[0].Value等于<span style="font-family: Arial, Helvetica, sans-serif;">(Zhang san)</span>;
 
<pre name="code" class="csharp">m.Groups[1].Value等于<span style="font-family: Arial, Helvetica, sans-serif;">Zhang san</span>;