我想批量替换后的图片地址为 <IMG src="http://www.myname.com/upload/1.jpg" border=0>
先定义个string outhost=www.myname.com; 怎么写正则表达式匹配呢?
info1.Content=Regex.Replace(info1.Content, "<img src.*?>)?", @"<img src"+outhost+".*?>)?",RegexOptions.IgnoreCase);
5 个解决方案
#1
try...
string outhost = "www.myname.com";
Regex reg = new Regex(@"(?is)(?<=<img\s+src=(['""]?))(?!http://)(?=[^'""\s>]+\1)");
string result = reg.Replace(yourStr, "http://" + outhost + "/");
#2
可是输出后还是:<IMG src="upload/2009_11/09112110144808.jpg" border=0> 没有加上去绝对地址啊
#3
给下你的代码,看看你是怎么用的
string test = "<IMG src=\"upload/2009_11/09112110144808.jpg\" border=0>";
string outhost = "www.myname.com";
Regex reg = new Regex(@"(?is)(?<=<img\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>
*/
#4
info1是实例化实体 info1.content 相当于test
string outhost=System.Configuration.ConfigurationSettings.AppSettings["OutIP"].ToString()+"sbd2010/";
Regex reg = new Regex(@"(?is)(?<=<img\s+src=(['""]?))(?!http://)(?=[^'""\s>]+\1)");
string result = reg.Replace(info1.Content, outhost);
下断点获得值为:"<IMG src="upload/091123144496680.gif" border=0>"
string outhost=System.Configuration.ConfigurationSettings.AppSettings["OutIP"].ToString()+"sbd2010/";
Regex reg = new Regex(@"(?is)(?<=<img\s+src=(['""]?))(?!http://)(?=[^'""\s>]+\1)");
string result = reg.Replace(info1.Content, outhost);
下断点获得值为:"<IMG src="upload/091123144496680.gif" border=0>"
#5
用EmEditor
批量正则
<img[^>]*?src\s*=\s*["']?([^"'\s>]*)[^>]*>
替换为
空
批量正则
<img[^>]*?src\s*=\s*["']?([^"'\s>]*)[^>]*>
替换为
空
#1
try...
string outhost = "www.myname.com";
Regex reg = new Regex(@"(?is)(?<=<img\s+src=(['""]?))(?!http://)(?=[^'""\s>]+\1)");
string result = reg.Replace(yourStr, "http://" + outhost + "/");
#2
可是输出后还是:<IMG src="upload/2009_11/09112110144808.jpg" border=0> 没有加上去绝对地址啊
#3
给下你的代码,看看你是怎么用的
string test = "<IMG src=\"upload/2009_11/09112110144808.jpg\" border=0>";
string outhost = "www.myname.com";
Regex reg = new Regex(@"(?is)(?<=<img\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>
*/
#4
info1是实例化实体 info1.content 相当于test
string outhost=System.Configuration.ConfigurationSettings.AppSettings["OutIP"].ToString()+"sbd2010/";
Regex reg = new Regex(@"(?is)(?<=<img\s+src=(['""]?))(?!http://)(?=[^'""\s>]+\1)");
string result = reg.Replace(info1.Content, outhost);
下断点获得值为:"<IMG src="upload/091123144496680.gif" border=0>"
string outhost=System.Configuration.ConfigurationSettings.AppSettings["OutIP"].ToString()+"sbd2010/";
Regex reg = new Regex(@"(?is)(?<=<img\s+src=(['""]?))(?!http://)(?=[^'""\s>]+\1)");
string result = reg.Replace(info1.Content, outhost);
下断点获得值为:"<IMG src="upload/091123144496680.gif" border=0>"
#5
用EmEditor
批量正则
<img[^>]*?src\s*=\s*["']?([^"'\s>]*)[^>]*>
替换为
空
批量正则
<img[^>]*?src\s*=\s*["']?([^"'\s>]*)[^>]*>
替换为
空