在文章信息中有如下代码:<table width="96%" border="0" align="center" cellpadding="0" cellspacing="0">
    <tr>
        <td id="HText" class="ArticleText"><p align="center"><img alt="" hspace="0" src="/DownFiles/Image/2008-01-08/200818924312981_0.jpg" align="baseline" border="0" /></p>
<p align="center">&nbsp;</p>
        </td>
    </tr>
</table>由于图片文件移到另外一台服务器上了,因此需要在图片地址前加入:http://192.168.1.17:8888/
有上面代码可知需要把/DownFiles/Image/2008-01-08/200818924312981_0.jpg替换成http://192.168.1.17:8888/DownFiles/Image/2008-01-08/200818924312981_0.jpg
--------
请问如何用正则表达式把信息内容里面的图片地址都加上http://192.168.1.17:8888呢?
--
在线等,谢谢~~~

解决方案 »

  1.   

    参考 string regex = "(?<=<img[\\s\\S]*src=\")[^\"]*?(?=\")";
                string con = "<img alt=\"\" hspace=\"0\" src=\"/DownFiles/Image/2008-01-08/200818924312981_0.jpg\" align=\"\" border=\"0\" />";
                string result = System.Text.RegularExpressions.Regex.Replace(con, regex, "http://192.168.1.17:8888$0");
                MessageBox.Show(result);
      

  2.   

    http://www.programfan.com/club/showpost.asp?id=24939
      

  3.   

    这个帖子也可以参考下
    http://topic.csdn.net/u/20071207/16/7b765642-13d0-48e4-9ae3-a0d95ae895df.html
      

  4.   

    你可以这样写,首先查找出所有的src=""这个属性即这种格式<img(.+?)src="(.+?)"
    然后替换成'//这是所有的正文
     String content="<img alt=\"\" hspace=\"0\" src=\"/DownFiles/Image/2008-01-08/200818924312981_0.jpg\" align=\"baseline\" border=\"0\">";'//这是要查找出所有的img对象
    regex = new Regex("<img(.+?)src=\"(.+?)\"");//下面是替换的结果
    Response.Write(regex.Replace(content,"<img$1src=\"http://192.168.1.17:8888$2\""));已测试