原字符串:
回复任意宝贝关键字即可进行店铺内搜索,您也可以直接前往[url title="a"]http://aa.com[/url]或[url title="b"]http://bb.com[/url]选购礼品~喜欢替换成:
回复任意宝贝关键字即可进行店铺内搜索,您也可以直接前往<a href="http://aa.com" target="_blank">a</a>或a href="http://bb.com" target="_blank">b</a>选购礼品~写法:
<meta charset="utf-8" />
<script type="text/javascript" src="http://code.jquery.com/jquery-1.7.2.min.js"></script>
<textarea id="a" style="width:300px;height:150px;">
回复任意宝贝关键字即可进行店铺内搜索,您也可以直接前往[url title="淘宝"]http://jm-all.taobao.com[/url]或[url title="拍拍"]http://m.wanggou.com/p/shop/home.xhtml?shopId=1114948892[/url]选购礼品~
</textarea>
<br>
<span id="b"></span><script type="text/javascript">
var text = $('#a').val();
text = text.replace(/\[url title="(.*)"\](.*)\[\/url\]/g, "<a href='$2' target='_blank' >$1</a>");
$('#b').html(text);
</script>这么写替换不了。不知道该怎么写