Lsua <IMG alt="太棒了 (Y)" src="http://localhost:55004/Message/images/face/face40.gif">Hdfg<IMG alt="太差了 (N)" src="http://localhost:55004/Message/images/face/face41.gif">Tige<IMG alt="哭泣的脸 :" src="http://localhost:55004/Message/images/face/face10.gif" (?>Gold
比如上面这段话怎么把<>中的内容都替换掉,规则是:打个比方:<IMG alt="太棒了 (Y)" src="http://localhost:55004/Message/images/face/face40.gif">替换成face40.gif,(注:<>中的内容是不确定的)给点意见也行,我不知道有多少分,有多少给多少,帮帮忙
比如上面这段话怎么把<>中的内容都替换掉,规则是:打个比方:<IMG alt="太棒了 (Y)" src="http://localhost:55004/Message/images/face/face40.gif">替换成face40.gif,(注:<>中的内容是不确定的)给点意见也行,我不知道有多少分,有多少给多少,帮帮忙
Dim result As String = Regex.Replace("yourStr",strPatten,"你要替换的内容",RegexOptions.None)
string strPatten="<.*?>"; //正则表达式
string result = Regex.Replace("yourStr",strPatten,"你要替换的内",RegexOptions.None);
IMG alt="太棒了 (Y)" src="http://localhost:55004/Message/images/face/face40.gif">替换成face40.gif
string str = @"Lsua <IMG alt=""太棒了 (Y)"" src=""http://localhost:55004/Message/images/face/face40.gif"">Hdfg<IMG alt=""太差了 (N)"" src=""http://localhost:55004/Message/images/face/face41.gif"">Tige<IMG alt=""哭泣的脸 :"" src=""http://localhost:55004/Message/images/face/face10.gif"">";
string result = Regex.Replace(str, @"(?is)<img[^>]*?src=(['""\s]?)[^'""]*/([^'""\s]+)\1[^>]*?>", "$2");
Console.WriteLine(result);
//Lsua face40.gifHdfgface41.gifTigeface10.gif
<script type="text/javascript">
var str = "Lsua <IMG alt=\"太棒了 (Y)\" src=\"http://localhost:55004/Message/images/face/face40.gif\">Hdfg<IMG alt=\"太差了 (N)\" src=\"http://localhost:55004/Message/images/face/face41.gif\">Tige<IMG alt=\"哭泣的脸 :\" src=\"http://localhost:55004/Message/images/face/face10.gif\">";
var reg = /<img[^>]*?src=(['""\s]?)[^'""]*\/([^'""\s]+)\1[^>]*?>/ig;
document.write(str.replace(reg,"$2"));
</script>
//Lsua face40.gifHdfgface41.gifTigeface10.gif
{ string pattren = @"<img[^>]+(src)\s*=\s*""?([^ "">]+)""?(?:[^>]+([^"">]+)""?)?>";
Regex regex = new Regex(pattren);
Match match = regex.Match(content);
if (match.Success)
{
//Response.Write(match.Groups[0]);
string img = match.Groups[0].ToString();
string str = content.Replace(img, img.Substring(0, img.LastIndexOf('>')) + " original=\"" + match.Groups[2].ToString() + "\">");
return str;
}
else
{
return content;
}
}可以参考一下,先使用正则表达式找到你的src的东西,在使用replace方法替换掉就ok了。
比如说就是
Lsua <IMG alt="太棒了 (Y)" src="http://localhost:55004/Message/images/face/face40.gif">Hdfg
再帮下大哥救星啊T T ,等下哈,虽然固定了,但是确实是及时雨啊
var str = "Lsua <IMG alt=\"太棒了 (Y)\" src=\"http://localhost:55004/Message/images/face/face40.gif\">Hdfg";
var reg = /<img[^>]*?src=(['""\s]?)[^'""]*\/([^'""\s]+)\1[^>]*?>/ig;
document.write(str.replace(reg,"$2"));
</script>
//Lsua face40.gifHdfg
中的$2是什么意思?比如想给换成@face40.gif@的话在哪里加什么东西么?
你可以看看过客大婶的博客。里面有很详细的讲解正则
<IMG src="http://localhost:55004/Message/images/face/face40.gif">
不过要在后台C#写。本来就不会,现在更蒙圈了(face40也是不确定 可能是face01 也可能是face15)