我的字符串是一个SQL语句,我想要把传入的参数名字及条件给过滤出来,这样可以根据传入的不同参数获取不同的SQL语句,比如:
string sql = @"select * from A left join B on A.ID=B.FID where ID=@par1 and Name=@par2";
我要的效果是 @par1,ID=@par1 ;
             @par2,Name=@par2";
各位高手帮帮忙哈

解决方案 »

  1.   


    "[^\s=]+\s*=\s*(@[^\s]+)"Groups[1].Value + ", " + Groups[0].Value;
      

  2.   


    这个正则,可以获取到ID=@par1 ,Name=@par2 ; 可是Groups[1].Value是什么,Groups是什么,我对正则很陌生,能否讲讲?
      

  3.   

    string result = Regex.Replace(sql,@"(\w+=)(@\w+)","$2,$0;");
      

  4.   


    Regex re = new Regex("[^\s=]+\s*=\s*(@[^\s]+)");
    Match m = Regex.Match(input);
    while (m.Success)
    {
        Console.WriteLine(m.Groups[1].Value + ", " + m.Groups[0].Value);
        m = m.NextMatch();
    }
      

  5.   

    唉,没测试好,要是
    string sql = @"select * from A left join B on A.ID=B.FID where ID like @par1 and Name=@par2";
    这样就不行了,好多种情况呢,有没有通用的呢