日期:2014-05-17  浏览次数:20509 次

求个C#的正则表达式

select count(0) from Ship where 1=1  
and SCode=@SCode
and OCode=@OCode
and (SCode=@SCode OR SCode=@SCode)
and SCode=@SCode 
or SCode like '%'+@SCode+'%'

其中已知:and ?=@SCode 或or ?=@SCode

目的删除SQL语句的条件=号前面是未知的

要C#的正则表达式

------解决方案--------------------
没看明白.
------解决方案--------------------
模糊
是要这个效果吗?
C# code

string sql=@"select count(0) from Ship where 1=1   
and SCode=@SCode
and OCode=@OCode
and (SCode=@SCode OR SCode=@SCode)
and SCode=@SCode  
and ?=@SCode or ?=@SCode
or SCode like '%'+@SCode+'%'";
sql=Regex.Replace(sql,@"(?i)(and \?=@SCode)|(or \?=@SCode)",""); 
/*
select count(0) from Ship where 1=1   
and SCode=@SCode
and OCode=@OCode
and (SCode=@SCode OR SCode=@SCode)
and SCode=@SCode  
or SCode like '%'+@SCode+'%'
*/

------解决方案--------------------
C# code
string pattern = @"(and|or)\s*\?=@SCode";

------解决方案--------------------
(?i)(and\s*\?=@SCode)|(or\s*\?=@SCode)试试,
你最好给个例子,说你要的结果
------解决方案--------------------
说的啥子哟
------解决方案--------------------
cmd.CommandText=sql;
cmd.SqlParameters.AddRange(paras);
Regex(cmd.CommandText,"and\s+\w+=null"," ");
------解决方案--------------------
这哥们
我不知道你说的什么啊。
------解决方案--------------------
不知所云啊

描述不清楚就给例子,并给出对应的结果,一定要给结果