正则匹配 sql语句参数

List<string> listcommand = new List<string>();
string sql = "update BMDMB set bmdmb_name=:bmdmb_name,parent_id=:parent_id where bmdmb_id=:bmdmb_id ";
            //string pattern = "(?is)(?<=" + Regex.Escape(":") + ").+?(?=" + Regex.Escape(",") + ")";
            //Regex reg = new Regex(@"(?<!@)[^w$#@]@(?!@)[w$#@]+");
            //reg.Match(yourStr).Value;//就是你要的 //@"(?<!@:)[^w$#@:]:(?!@:)[w$#@:]+"
            MatchCollection mats = Regex.Matches(sql, @"(?<p>:w+)");//@"[^@@](?<p>@w+)"
            foreach (Match mat in mats)
            {
                listcommand.Add(mat.Value);
            }

  结果

:bmdmb_name
:parent_id
:bmdmb_id

  

原文地址:https://www.cnblogs.com/gxivwshjj/p/5160069.html