var str = '@username(123) test@username2(234) test'
var newstr = '<a href="localhost/home/userid=123">username</a>test<a href="localhost/home/userid=234">username2</a>test'
我怎么能做到这一点在javascript中使用正则表达式
var str = '@username(123) test@username2(234) test'
var newstr = '<a href="localhost/home/userid=123">username</a>test<a href="localhost/home/userid=234">username2</a>test'
我怎么能做到这一点在javascript中使用正则表达式
var str = '@username(123) test@username2(234) test'
document.write(str.replace(/@(\w+?)\((\d+?)\)/g, '<a href="localhost/home/userid=$2">$1</a>'));
// Result: <a href="localhost/home/userid=123">username</a> test<a href="localhost/home/userid=234">username2</a> test