再求正则

小D2013 2012-02-29 11:32:20
有sql 语句 大致是下面这样

select * from tablea where name like %s

select * from tablea where id = s

%s 和 s 是 参数,要替换成:张三

select * from tablea where name like '%张三'

select * from tablea where id = '张三'



...全文
84 3 打赏 收藏 转发到动态 举报
写回复
用AI写文章
3 条回复
切换为时间正序
请发表友善的回复…
发表回复
-过客- 2012-02-29
  • 打赏
  • 举报
回复
try...

            string test = @"select * from tablea where name like %s  

select * from tablea where id = s ";
Regex reg = new Regex(@"(%?)\bs\b");
string result = reg.Replace(test, "'$1张三'");
richTextBox2.Text = result;
EnForGrass 2012-02-29
  • 打赏
  • 举报
回复
[Quote=引用 1 楼 bdmh 的回复:]

没有细致完善,条件是 s后面没有单词字符匹配
C# code

//string s = "select * from tablea where name like %s ";
string s = "select * from tablea where id = s ";
Regex reg = new Regex……
[/Quote]
其实用不着用正则,既然是参数,传值不就行了
bdmh 2012-02-29
  • 打赏
  • 举报
回复
没有细致完善,条件是 s后面没有单词字符匹配

//string s = "select * from tablea where name like %s ";
string s = "select * from tablea where id = s ";
Regex reg = new Regex(@"s[\W]");
s = reg.Replace(s, "张三");

110,536

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • Web++
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

试试用AI创作助手写篇文章吧