求正则?

echoxue 2012-08-03 04:02:16
ContractName='aaaaa',contractRole='Web master',CtUpdate='02/02/2012'update=now()

要求,把=后面的数据作为一个字符串返回,
string result = 'aaaaa','Web master','02/02/2012','now()'

谢谢!!


return_false不知道在吗????
...全文
107 6 打赏 收藏 转发到动态 举报
写回复
用AI写文章
6 条回复
切换为时间正序
请发表友善的回复…
发表回复
echoxue 2012-08-04
  • 打赏
  • 举报
回复
TO Return_false,

要考虑里面含有,的数据该如何处理啊???
例如:
string temp = "Contrac,tName='aa,aaa',contractRole='Web, master',CtUpdate='02/02/2012',update=now(),ssss='sdsa,ss',ttt=2";
  • 打赏
  • 举报
回复
修改一下
  string temp = "ContractName='aaaaa',contractRole='Web master',CtUpdate='02/02/2012',update=now(),ssss='sdsass',ttt=2";
string[] result = Regex.Matches(temp, @"(?<=='?)[^',]+(?='|,|\s|$)").Cast<Match>().Select(a => a.Value).ToArray();
/*
[0] "aaaaa" string
[1] "Web master" string
[2] "02/02/2012" string
[3] "now()" string
[4] "sdsass" string
[5] "2" string

*/
  • 打赏
  • 举报
回复
  string temp = "ContractName='aaaaa',contractRole='Web master',CtUpdate='02/02/2012',update=now(),ssss='sdsass'";
string[] result = Regex.Matches(temp,@"(?<=='?)[^',\s]+(?='|,|\s)").Cast<Match>().Select(a=>a.Value).ToArray();
/*
[0] "aaaaa" string
[1] "Web" string
[2] "02/02/2012" string
[3] "now()" string
[4] "sdsass" string

*/
  • 打赏
  • 举报
回复
给你来个非正则的
string str = "ContractName='aaaaa',contractRole='Web master',CtUpdate='02/02/2012',update=now(),ssss='sdsass'";

var s= str.Split(',').Where(t => t.Trim() != "").Select(t => t.Split('=')[1]).ToArray();
echoxue 2012-08-03
  • 打赏
  • 举报
回复
[Quote=引用 1 楼 的回复:]

(?<=[^=]+=(['"]?))[^'"]+(?=\1)
[/Quote]

不对啊,如果数据是ContractName='aaaaa',contractRole='Web master',CtUpdate='02/02/2012',update=now(),ssss='sdsass'

就有问题了
q107770540 2012-08-03
  • 打赏
  • 举报
回复
(?<=[^=]+=(['"]?))[^'"]+(?=\1)

110,538

社区成员

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

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

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