正则表达式替换img标签src值!!!

方法一:spa

相关连接:http://bbs.csdn.net/topics/320185735.net

实例:此实例本身作的时候讲字符串加了alt进行了有关修改  不清楚看上面连接code

string test = "<IMG alt="" src=\"/upload/2009_11/09112110144808.jpg\" border=0>";

string outhost = "www.myname.com";

Regex reg = new Regex(@"(?is)(?<=<img\b[^>]*?src=mg\s+src=(['""]?))(?!http://)(?=[^'""\s>]+\1)");

string result = reg.Replace(test, "http://" + outhost );

/*----------输出------------

<IMG src="http://www.myname.com/upload/2009_11/09112110144808.jpg" border=0>

*/ci

 

方法二:字符串

 

相关连接:http://bbs.csdn.net/topics/390866982 get

 

public static string ReplaceImgPath(string intro)
        {
            string imgPath = string.IsNullOrEmpty(PubConfig.SportQuanWeb) ? "/" : PubConfig.SportQuanWeb;
            Regex reg = new Regex(@"(?i)(?<=<img\b[^>]*?src=\s*(['""]?))([^'""]*/)+(?=[^'""/]+\1)");
            return reg.Replace(intro, imgPath);
        }

如上面代码只实现替换文件名前面的src,与实际效果不符合;

实际要求:

字符串infro包含不少img标签,例如<img alt="" src="/UserFiles/files/120CAOKY6QZ.jpg" style="width: 120px; height: 120px;" />

调用此方法后全部的img标签应该是这样的<img alt="" src="http://198.168.1.2/UserFiles /files/120CAOKY6QZ.jpg" style="width: 120px; height: 120px;" />string

相关文章
相关标签/搜索