javascript替换不按预期工作

时间:2011-11-22 09:46:59

标签: javascript replace

    <pre>
    SMTP -> get_lines(): $data was ""


       "

    SMTP -> get_lines(): $data was "250-smtp.webfaction.com

    250-VRFY

    "


    "

     "

    SMTP -> get_lines(): $data is "334 UGFzc3dvcmQ6

    "

    SMTP -> get_lines(): $data was ""

    SMTP -> get_lines(): $str is "235 2.0.0 Authentication successful

    "
    very long message here


    </pre>{"message":"My message.","status":1}

在某些情况下,要替换的邮件可以是</pre>{"message":"My message.","status":1}

在这两种情况下,都应由{"message":"My message.","status":1}

替换

我正在做这样的事情msg = msg.replace(/^[<pre>]*[.]*<\/pre>{/m, '{'));

但它不起作用......需要一些帮助

2 个答案:

答案 0 :(得分:2)

试试这个:

msg = msg.replace(/^[\s\S]*<\/pre>({[^}]*})/, '$1')

答案 1 :(得分:0)

只需从正则表达式中删除^,因为您不需要匹配字符串beggining。