怎么用正则表达式提取所有sql参数化语句的变量
如何用正则表达式提取所有sql参数化语句的变量?
如where UserName=@User_$#@Name,提取出@User_$#@Name
参数化命名规则
只能包含字母、数字和_、$、#、@四个特殊字符,并且@不能在在开头同时存在,即@@User_$#@Name就不行(防止和select @@identity冲突)@User_$#@@Name也是可以的
网上找到的一种,但是没有考虑特殊字符的问题
List<string> result = new List<string>();
Regex paramReg = new Regex(@"[^@@](?<sqlParam>@\w+)");
MatchCollection matches = paramReg.Matches(sql);
foreach (Match m in matches)
Response.Write(m.Groups["sqlParam"].Value + ",");
正则表达式不是很清楚,希望大家帮忙下。
------解决方案--------------------
+1 等正则高手
------解决方案--------------------
------解决方案--------------------
怎么可能只得到逗号呢,我给你的那个表达式根本匹配不到逗号。
------解决方案--------------------
如where UserName=@User_$#@Name,提取出@User_$#@Name
参数化命名规则
只能包含字母、数字和_、$、#、@四个特殊字符,并且@不能在在开头同时存在,即@@User_$#@Name就不行(防止和select @@identity冲突)@User_$#@@Name也是可以的
网上找到的一种,但是没有考虑特殊字符的问题
List<string> result = new List<string>();
Regex paramReg = new Regex(@"[^@@](?<sqlParam>@\w+)");
MatchCollection matches = paramReg.Matches(sql);
foreach (Match m in matches)
Response.Write(m.Groups["sqlParam"].Value + ",");
正则表达式不是很清楚,希望大家帮忙下。
------解决方案--------------------
+1 等正则高手
------解决方案--------------------
------解决方案--------------------
怎么可能只得到逗号呢,我给你的那个表达式根本匹配不到逗号。
------解决方案--------------------