一个字符串中有
some str1<a href='www.baidu.com'>baidu</a>some str2<a href='www.qq.com'>tencent</a>some str3
怎么能转化成
some str1[url=www.baidu.com]baidu[/url]some str2[url=www.qq.com]tencent[/url]some str3
这样的?
var a="some str1<a href='www.baidu.com'>baidu</a>some str2<a href='www.qq.com'>tencent</a>some str3";
var pattern = /<a.*?href='(.*?)'>(.*?)<\/a>/g;
alert(a.replace(pattern,"[url=$1]$2[/url]"))