问一个正则表达式 双引号中间的任意字符串,怎么写正则如:sdfsfsfsf"dssss \r sdf\n \\ // s d在要工 \r"asdfawsd"fsfws"ef要找出"dssss \r sdf\n \\ // s d在要工 \r"和"fsfws" 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 try... Regex reg = new Regex(@"""[^""]*"""); MatchCollection mc = reg.Matches(yourStr); foreach (Match m in mc) { richTextBox2.Text += m.Value + "\n----------\n"; } string str = "sdfsfsfsf\"dssss \r sdf\n \\ // s d在要工 \r\"asdfawsd\"fsfws\"ef"; System.Text.RegularExpressions.Regex reg = new Regex(@"""([^""]*)""", System.Text.RegularExpressions.RegexOptions.IgnoreCase); System.Text.RegularExpressions.Match match = reg.Match(str); while (match.Success) { string ret = match.Value; match = match.NextMatch(); } 字符串中间还有这样的转义那就加上\\""相或就行了如下: string str = "sdfsfsfsf\"dssss\\\" \r sdf\n \\ // s d在要工 \r\"asdfawsd\"fsfws\"ef"; System.Text.RegularExpressions.Regex reg = new Regex(@"""([^""|^\\""]*)""", System.Text.RegularExpressions.RegexOptions.IgnoreCase); System.Text.RegularExpressions.Match match = reg.Match(str); while (match.Success) { string ret = match.Value; str = str.Replace(ret, ret + "<br/>"); match = match.NextMatch(); } 试下,有不满足的给出实例 Regex reg = new Regex(@"""([^""\\]|\\""|\\\\)*"""); MatchCollection mc = reg.Matches(yourStr); foreach (Match m in mc) { richTextBox2.Text += m.Value + "\n----------\n"; }现在开始的"前面是否为\没有做限制,一会回去再补充 现在出的问题是:ayersAll(),"中文.") sdfsf (),"|CFF20C .|r\n") call 出来的字符串是"中文."") call ...... new Regex(@"""(\\""|""""|.)*""")串中可含 \" 或 "" 这样写:new Regex(@"""(\""|""""|.)*""") 还是会出现"Mid\n",sdfsf,"Uncle !? What's wrong with you?""Cid",sdfs,"Mid...no, not that…err…AARRGGHH!!!" 呵呵,再加个问号:new Regex(@"""(\""|""""|.)*?""") good ! 能解释一下吗辛苦了 try...Regex reg = new Regex(@"""([^""\\]|\\""|\\)*""");MatchCollection mc = reg.Matches(yourStr);foreach (Match m in mc){ richTextBox2.Text += m.Value + "\n----------\n";}不过还不够严谨,再补充 本帖最后由 lxcnn 于 2010-04-22 22:59:25 编辑 本帖最后由 lxcnn 于 2010-04-22 23:06:54 编辑 sorry,我太勿忙了,对不起楼上的楼上的楼上了.只能说两位都辛苦了. 【新手求助】插入数据库出现问题= = 请问VISUAL studio 2005 以上的版本有没有类似DELPHI用的 CnWizards这样能在控件上能直接显示其控件名称的功能的插件。 如何写鼠标滚动事件? 调用另一个项目的Form 串口问题 c# 提示问题 急! C#怎么连上数据库啊 bit字段对应c#中的数据类型 请教在localhost/xxx.aspx运行,能正常显示treeview,但将其设置在internet上,比如219.128.98.7/xxx.aspx就不能正常显示treeview为什么 想写一个《用C#编写小游戏》之类的书,不知能不能卖到钱 C#如何读取dat文件? 删除不管用
MatchCollection mc = reg.Matches(yourStr);
foreach (Match m in mc)
{
richTextBox2.Text += m.Value + "\n----------\n";
}
{
string ret = match.Value;
match = match.NextMatch(); }
string str = "sdfsfsfsf\"dssss\\\" \r sdf\n \\ // s d在要工 \r\"asdfawsd\"fsfws\"ef"; System.Text.RegularExpressions.Regex reg = new Regex(@"""([^""|^\\""]*)""", System.Text.RegularExpressions.RegexOptions.IgnoreCase); System.Text.RegularExpressions.Match match = reg.Match(str); while (match.Success)
{
string ret = match.Value;
str = str.Replace(ret, ret + "<br/>");
match = match.NextMatch(); }
MatchCollection mc = reg.Matches(yourStr);
foreach (Match m in mc)
{
richTextBox2.Text += m.Value + "\n----------\n";
}现在开始的"前面是否为\没有做限制,一会回去再补充
现在出的问题是:
ayersAll(),"中文.")
sdfsf
(),"|CFF20C
.|r\n")
call 出来的字符串是
"中文."
")
call ......
new Regex(@"""(\""|""""|.)*""")
还是会出现
"Mid\n",sdfsf,"Uncle !? What's wrong with you?"
"Cid",sdfs,"Mid...no, not that…err…AARRGGHH!!!"
new Regex(@"""(\""|""""|.)*?""")
good ! 能解释一下吗
辛苦了
MatchCollection mc = reg.Matches(yourStr);
foreach (Match m in mc)
{
richTextBox2.Text += m.Value + "\n----------\n";
}不过还不够严谨,再补充