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