在 JavaScript 正则表达式中,例如如何转入
Check out http://example.com/foobar#123
进入
Check out <a href="http://example.com/foobar#123">example.com/foobar#123</a>
谢谢!
最佳答案
使用此替换调用:
s = 'Check out http://example.com/foobar#123';
repl = s.replace(/(https?:\/\/(\S+))/i, "<a href='$1'>$2</a>");
//=> Check out <a href='http://example.com/foobar#123'>example.com/foobar#123</a>
关于JavaScript:链接 URL,但从显示的链接文本中删除 'http://',我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19927495/