程序已经弄好了,但是有个地方不是很动原理,请讲解一下
string strTmp= " <img src=\ "aaa.jpg\ " border=0> <br> <p> <img src=\ "bbb.jpg\ " border=0 > <br> ".Replace( " ", " ");
MatchCollection mc = Regex.Matches(strTmp, @ " <img\s+[^> ]*src= " "(? <img> [^ " "]*?) " "[^> ]*?> ", RegexOptions.IgnoreCase);
为什么正则= " "(? <img> [^ " "]*?) " "
前后都有两个 " "
------解决方案--------------------因为前面有@,所以要用 " "对 "进行转义
如果前面不加@,那么就需要用\ "对 "进行转义了
等价于
MatchCollection mc = Regex.Matches(strTmp, " <img\\s+[^> ]*src=\ "(? <img> [^\ "]*?)\ "[^> ]*?> ", RegexOptions.IgnoreCase);
也就是用来匹配字符 "本身的