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,(注:<>中的内容是不确定的)给点意见也行,我不知道有多少分,有多少给多少,帮帮忙

解决方案 »

  1.   

    Dim strPatten As String="<.*?>" '正则表达式
    Dim result As String = Regex.Replace("yourStr",strPatten,"你要替换的内容",RegexOptions.None)
      

  2.   

    c#
    string strPatten="<.*?>"; //正则表达式
    string result = Regex.Replace("yourStr",strPatten,"你要替换的内",RegexOptions.None);
      

  3.   

    替换的内容是上边字符串里的最后一个文件名
    IMG alt="太棒了 (Y)" src="http://localhost:55004/Message/images/face/face40.gif">替换成face40.gif
      

  4.   


               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
      

  5.   


    <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 
      

  6.   

    private string GetImg(string content)
        {        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了。
      

  7.   

    单独一个还用改么?
    比如说就是
    Lsua <IMG alt="太棒了 (Y)" src="http://localhost:55004/Message/images/face/face40.gif">Hdfg 
    再帮下大哥救星啊T T ,等下哈,虽然固定了,但是确实是及时雨啊
      

  8.   

    改什么?把要替换的字符串换一下就可以了<script type="text/javascript">
    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 
      

  9.   

    问下 document.write(str.replace(reg,"$2"));
    中的$2是什么意思?比如想给换成@face40.gif@的话在哪里加什么东西么?
      

  10.   

    document.write(str.replace(reg,"@$2@"));$2是捕获的组,从第一个大括号开始,第一个为组1,可以用$1表示。
    你可以看看过客大婶的博客。里面有很详细的讲解正则
      

  11.   

    http://blog.csdn.net/lxcnn/
      

  12.   

    = =还在么,刚刚成功替换了,现在想把[p:face40] 换成:
    <IMG src="http://localhost:55004/Message/images/face/face40.gif"> 
    不过要在后台C#写。本来就不会,现在更蒙圈了(face40也是不确定 可能是face01 也可能是face15)