static void Main(string[] args)
        {
            string str = "{a,1},{b,2},{c,3}";
            Regex reg = new Regex("(?<=1}),+?");
            string []arr=reg.Split(str);
            
            foreach (string s in arr)
            {
                Console.WriteLine(s);
            }
            Console.ReadKey();
        }
我想把
{a,1},{b,2},{c,3}
拆成
{a,1}
{b,2}
{c,3}
应该怎么写?

解决方案 »

  1.   

    static void Split()
        {
            string str = "{a,1},{b,2},{c,3}";
            Regex reg = new Regex(@"(?<=\}),", RegexOptions.Compiled);
            string[] arr = reg.Split(str);        foreach (string s in arr)
            {
                Console.WriteLine(s);
            }
            Console.ReadKey();
        } 
      

  2.   

    这样也可以
    {[^{}]+}
    //code
    string s = "{a,1},{b,2},{c,3}";
    MatchCollection mc = Regex.Matches(s,"{[^{}]+}");
    foreach(Match m in mc)
    {
        MessageBox(m.Value);
    }