文件中很多这种:map('','','','','-8','1')的字符有很多形式,最后两个''里一定有前符,前面的不一定有,例如:
map('','','','','4','1')
map('1','3','','','9','1')
map('','3','4','5','8','1')请问我怎么把文件里面的最后两个''中的字符中提出来?以示例来说,我就是要提取出“4,1”、“9,1”、“8,1”这三组数字,谢谢

解决方案 »

  1.   

    Regex reg=new Regex(@"(?<=map\(('\d*',)*)'\d+','\d+'(?=\))");
      

  2.   


                Regex r = new Regex(@"map\(('(-?)[0-9]*',)*?'(?<text1>(-?)[0-9]*)','(?<text2>(-?)[0-9]*)'\)");
                string abc = "";
                foreach (Match m in r.Matches(text))
                {
                    abc += m.Groups["text1"].Value.ToString();
                    abc += ",";
                    abc += m.Groups["text2"].Value.ToString();
                    abc += "\r\n";
                }
                MessageBox.Show(abc);
      

  3.   


    不好意思,刚才吃饭去了。。Regex reg=new Regex(@"map\((?:'\d*',)*'(\d+)','(\d+)'\)");
    string result=string.Empty;
    string text="文件内容";
    foreach (Match m in reg.Matches(text))
    {
       result+=m.Group[1].Value+","+m.Group[2].Value+"\r\n";
    }