求一正则表达式的问题 内容:尊敬的[张三]先生,你至今为止还欠费[1000]元,请及时缴清!如何有正则表达式把[]括号内的文字取出有逗号连接。谢谢! 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 public Regex MyRegex = new Regex( "\\[([^\\]]+)\\]", RegexOptions.IgnoreCase | RegexOptions.CultureInvariant | RegexOptions.IgnorePatternWhitespace | RegexOptions.Compiled ); fancyf(凡瑞) 的表达式可以,但读出来时不方便,因为他把前者和后者混在一起了可以这样string str = "尊敬的[张三]先生,你至今为止还欠费[1000]元,请及时缴清!";Regex MyRegex = new Regex(@"\[(?<name>[^\]]+)\].+\[(?<money>[\d]+)\]");Match match = MyRegex.Match(str);string outstr = match.Groups["name"].Value + "," + match.Groups["money"].Value;Console.WriteLine(outstr);结果: 张三,1000 急求,C#网站访问量统计? API WriteFile和readFile 返回错误:无效句柄 关于C#的程序帮忙解释下 自定义ListView控件 “找不到可安装的ISAM” VS.net2005编写SQL SERVER2005扩展存储过程的问题 网络程序的数据一般放在数据库中,请问各位一般软件的数据放在哪里啊 用鼠标在窗体写字 大家开发时,是不是把每一层的类都建成类库的形式,在程序中调用类库? DrawString方法如何设置行距和间距这些参数呢? 关于Report Services RDL的一个问题 如何在C#里直接调用excel的合并单元格命令?
"\\[([^\\]]+)\\]",
RegexOptions.IgnoreCase
| RegexOptions.CultureInvariant
| RegexOptions.IgnorePatternWhitespace
| RegexOptions.Compiled
);
但读出来时不方便,因为他把前者和后者混在一起了
可以这样string str = "尊敬的[张三]先生,你至今为止还欠费[1000]元,请及时缴清!";
Regex MyRegex = new Regex(@"\[(?<name>[^\]]+)\].+\[(?<money>[\d]+)\]");
Match match = MyRegex.Match(str);
string outstr = match.Groups["name"].Value + "," + match.Groups["money"].Value;
Console.WriteLine(outstr);结果: 张三,1000