正则表达式

hjx398 2012-05-28 10:07:23
var s = "create(new a());";
s = System.Text.RegularExpressions.Regex.Replace(ss, @"create\([^\(\);\)]+", "$0,_游戏类型",System.Text.RegularExpressions.RegexOptions.Multiline);
//输出
//create(new a,_游戏类型());
//可我想要的结果是:
//create(new a(),_游戏类型);
...全文
101 5 打赏 收藏 转发到动态 举报
写回复
用AI写文章
5 条回复
切换为时间正序
请发表友善的回复…
发表回复
EnForGrass 2012-05-28
  • 打赏
  • 举报
回复
[Quote=引用 4 楼 的回复:]

引用 2 楼 的回复:

s = System.Text.RegularExpressions.Regex.Replace(ss, @"create\([^\)]+\)", "$0,_游戏类型",System.Text.RegularExpressions.RegexOptions.Multiline);

这个是可以了,可是要是字符串是: ss = "create(new a(),n……
[/Quote]
正则改成这样
create\(.*(?=\))
hjx398 2012-05-28
  • 打赏
  • 举报
回复
[Quote=引用 2 楼 的回复:]

s = System.Text.RegularExpressions.Regex.Replace(ss, @"create\([^\)]+\)", "$0,_游戏类型",System.Text.RegularExpressions.RegexOptions.Multiline);
[/Quote]
这个是可以了,可是要是字符串是: ss = "create(new a(),new b());";
怎么才能得到://create(new a(),new b(),_游戏类型);
hjx398 2012-05-28
  • 打赏
  • 举报
回复
[Quote=引用 1 楼 的回复:]

create\(.+\)
[/Quote]
//请先验证一下
你的输出结果是 :
create(new a()),_游戏类型;
不是我要的结果
EnForGrass 2012-05-28
  • 打赏
  • 举报
回复
s = System.Text.RegularExpressions.Regex.Replace(ss, @"create\([^\)]+\)", "$0,_游戏类型",System.Text.RegularExpressions.RegexOptions.Multiline);
不懂装懂 2012-05-28
  • 打赏
  • 举报
回复
create\(.+\)

111,126

社区成员

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

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

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