本帖最后由 e8love 于 2011-12-12 10:47:18 编辑

解决方案 »

  1.   

    return msg.replace(/\[em:(.+?):]/ig, "<img src=\"static/images/face/emoticon/$1.gif\" class=\"face\" borderJs中是这样写的 现在 想写错 后台调用的方式Input = @"/\[em:(.+?):]/ig";
                string ReplsStr = "<img src=\"static/images/face/emoticon/$1.gif\" class=\"face\" border=\"0\">";            Regex Reg = new Regex(Input, RegexOptions.Singleline | RegexOptions.IgnoreCase);            if (Input == null) return "";
                return Reg.Replace(Input, ReplsStr).Trim();
    发现这样是不对 怎么改下 谢谢了
      

  2.   

    .NET 的正则不用 / / 来分隔,ig 参数也不能挂在正则式上,直接写 \[em:(.+?):\] 就好
      

  3.   

    还有,你调用的方式也不对,是 reg.Replace(msg, replsStr)
      

  4.   


    string img = "[em:icon/cloud.gif:]";
    string replsStr = "<img src=\"static/images/face/emoticon/$1.gif\" class=\"face\" border=\"0\">"; System.Text.RegularExpressions.Regex reg = new System.Text.RegularExpressions.Regex(@"\[em:(.+?):\]", System.Text.RegularExpressions.RegexOptions.Singleline | System.Text.RegularExpressions.RegexOptions.IgnoreCase);
    return reg.Replace(img, replsStr);
      

  5.   

    /\[em:(.+?):]/ig =>
    (?i)\[em:(.+?):\]
      

  6.   


    这里是对的 我的变量是 input 没有msg现在 处理过的结果是这样[<img src=\"static/images/face/emoticon/$1.gif\" class=\"face\" border=\"0\"><img src=\"static/images/face/emoticon/$1.gif\" class=\"face\" border=\"0\"><img src=\"static/images/face/emoticon/$1.gif\" class=\"face\" border=\"0\"><img src=\"static/images/face/emoticon/$1.gif\" class=\"face\" border=\"0\"><img src=\"static/images/face/emoticon/$1.gif\" class=\"face\" border=\"0\"><img src=\"static/images/face/emoticon/$1.gif\" class=\"face\" border=\"0\"><img src=\"static/images/face/emoticon/$1.gif\" class=\"face\" border=\"0\"><img src=\"static/images/face/emoticon/$1.gif\" class=\"face\" border=\"0\"><img src=\"static/images/face/emoticon/$1.gif\" class=\"face\" border=\"0\">]"
      

  7.   


    这个是有问题的 我改成
    Input =@“(?i)\[em:(.+?):\]”结果是 "(?i)\\[em:(.+?):\\]"Input =“(?i)[em:(.+?):]”结果是<img src=\"static/images/face/emoticon/$1.gif\" class=\"face\" border=\"0\"><img src=\"static/images/face/emoticon/$1.gif\" class=\"face\" border=\"0\"><img src=\"static/images/face/emoticon/$1.gif\" class=\"face\" border=\"0\"><img src=\"static/images/face/emoticon/$1.gif\" class=\"face\" border=\"0\"><img src=\"static/images/face/emoticon/$1.gif\" class=\"face\" border=\"0\"><img src=\"static/images/face/emoticon/$1.gif\" class=\"face\" border=\"0\"><img src=\"static/images/face/emoticon/$1.gif\" class=\"face\" border=\"0\"><img src=\"static/images/face/emoticon/$1.gif\" class=\"face\" border=\"0\"><img src=\"static/images/face/emoticon/$1.gif\" class=\"face\" border=\"0\">]"
    直接 Input = "(?i)\[em:(.+?):\]"; 提示转义有错
      

  8.   

    string img = "[em:icon/cloud.gif:]";
    我的字符串是 string img = "[em:50:]";
     img = "[em:0:]";这样的 应该怎么改下 
      

  9.   

    不用改,把 img 当参数往里面传就行了。格式匹配就会替换。