I am using the function below to match URLs inside a given text and replace them for HTML links.
(我正在使用下面的功能来匹配给定文本内的URL,并将其替换为HTML链接。)
The regular expression is working great, but currently I am only replacing the first match.(正则表达式效果很好,但目前我仅替换第一场比赛。)
How I can replace all the URL?
(如何替换所有URL?)
I guess I should be using the exec command, but I did not really figure how to do it.(我想我应该使用exec命令,但是我没有真正弄清楚该怎么做。)
function replaceURLWithHTMLLinks(text) {
var exp = /((https?|ftp|file)://[-A-Z0-9+&@#/%?=~_|!:,.;]*[-A-Z0-9+&@#/%=~_|])/i;
return text.replace(exp,"<a href='$1'>$1</a>");
}
ask by Sergio del Amo translate from so
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…