+ -
当前位置:首页 → 问答吧 → 一个UBB引用回复的正则表达式

一个UBB引用回复的正则表达式

时间:2011-09-20

来源:互联网

纠结中。。。。网上找了个解析的js   function,    
function   ubbQuote(str)   {
                return   str.replace(/\[quote\]([\s\S]+)\[\/quote\]/g,   function(s0,   s)   {
                        return   " <div   class=q> <div   class=q_t> 引用内容: </div> <div   class=q_c> "   +
          ubbQuote(s)   +   " </div> </div> ";
                });
        }
str传参为[quote]ok,好的[/quote],能够解析。但是我传参为[quote=引用4楼   管理员   的回复]ok,好的[/quote],怎么修改下那个function呢???我想在ubbQuote中能提取“=引用4楼   管理员   的回复”这个信息。。。各位大虾,求救!!!!

作者: zhoufeng0401   发布时间: 2011-09-20

JScript code
/\[quote[^\]]*\]([\s\S]+?)\[\/quote\]/g


给你后面那里也加了个?,否则多个时会出问题的

作者: sohighthesky   发布时间: 2011-09-20

在ubbQuote中能提取“=引用4楼 管理员 的回复”这个信息怎么获取啊?

作者: zhoufeng0401   发布时间: 2011-09-20

JScript code

        function ubbQuote(str) {
            return str.replace(/\[quote([^\]]*?)\]([\s\S]+)\[\/quote\]/g, function(s0, s1, s2) {
                return "<div class='q'><div class='q_t'>引用内容:" + s1.replace(/=|\s+/g, ' ') + "</div><div class='q_c'>" + ubbQuote(s2) + "</div></div>";
            });
        }
        var s = "[quote=引用4楼   管理员   的回复][quote=引用4楼   管理员   的回复]ok,好的[/quote][/quote]";
        alert(ubbQuote(s)); 

作者: danica7773   发布时间: 2011-09-20

相关阅读 更多