首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > .NET > C# >

程序已经弄好了,但是有个地方不是很动原理,请讲解一下,该怎么解决

2012-01-12 
程序已经弄好了,但是有个地方不是很动原理,请讲解一下stringstrTmp imgsrc\ aaa.jpg\ border0br

程序已经弄好了,但是有个地方不是很动原理,请讲解一下
string   strTmp= " <img   src=\ "aaa.jpg\ "   border=0> <br> <p> <img   src=\ "bbb.jpg\ "   border=0   > <br> ".Replace( "&nbsp; ", " ");
MatchCollection   mc   =   Regex.Matches(strTmp,   @ " <img\s+[^> ]*src= " "(? <img> [^ " "]*?) " "[^> ]*?> ",   RegexOptions.IgnoreCase);

为什么正则= " "(? <img> [^ " "]*?) " "
前后都有两个 " "

[解决办法]
因为前面有@,所以要用 " "对 "进行转义
如果前面不加@,那么就需要用\ "对 "进行转义了
等价于
MatchCollection mc = Regex.Matches(strTmp, " <img\\s+[^> ]*src=\ "(? <img> [^\ "]*?)\ "[^> ]*?> ", RegexOptions.IgnoreCase);

也就是用来匹配字符 "本身的

热点排行