有下面的字符串
(121.2,22.3)(121.23,22.5)(121.2,21.0)(122.1,21)需要获得每对括号里面的值,分别赋给两个变量 用正则表达式怎么实现?

解决方案 »

  1.   

    你贴的是全角。Regex re = new Regex("(?<=\\()(?<key>[^\\(,]+),(?<value>[^\\),]+)(?=\\))");
    MatchCollection mc = re.Matches("(121.2,22.3)(121.23,22.5)(121.2,21.0)(122.1,21)");
    foreach (Match ma in mc)
    {
        Console.WriteLine("{0}:{1}", ma.Groups["key"], ma.Groups["value"]);
    }
      

  2.   


    void Main()
    {
      string str=@"(121.2,22.3)(121.23,22.5)(121.2,21.0)(122.1,21)"; foreach(Match m in Regex.Matches(str,"[((]([^,]+),([^))]+)[))]"))
    {
    Console.WriteLine(string.Format("{0}\t{1}",m.Groups[1].Value,m.Groups[2].Value));
    }
    }/*
    121.2 22.3
    121.23 22.5
    121.2 21.0
    122.1 21
    */