用JavaScript检测文本中的URL是否有人建议检测一组字符串中的URL?arrayOfStrings.forEach(function(string){
// detect URLs in strings and do something swell,
// like creating elements with links.});最新情况:最后,我使用了这个用于链路检测…的正则表达式。显然几年后。kLINK_DETECTION_REGEX = /(([a-z]+:\/\/)?(([a-z0-9\-]+\.)+([a-z]{2}|aero|arpa|biz|com|coop|edu|gov|info|int|jobs|mil|museum|name|nato|net|org|pro|travel|local|internal))(:[0-9]{1,5})?(\/[a-z0-9_\-\.~]+)*(\/([a-z0-9_\-\.]*)(\?[a-z0-9+_\-\.%=&]*)?)?(#[a-zA-Z0-9!$&'()*+.=-_~:@/?]*)?)(\s+|$)/gi完整的助手(有可选的扶手支持)位于吉斯特#1654670.
3 回答
料青山看我应如是
TA贡献1772条经验 获得超8个赞
var urlRegex =/(\b(https?|ftp|file):\/\/[-A-Z0-9+&@#\/%?=~_|!:,.;]*[-A-Z0-9+&@#\/%=~_|])/ig;
function linkify(text) { var urlRegex =/(\b(https?|ftp|file):\/\/[-A-Z0-9+&@#\/%?=~_|!:,.;]*[-A-Z0-9+&@#\/%=~_|])/ig; return text.replace(urlRegex, function(url) { return '<a href="' + url + '">' + url + '</a>'; });}
添加回答
举报
0/150
提交
取消