js输入框识别超链接正则

function urlDistinguish(str){
  var reg = /(\b(https?|ftp|file):\/\/[-A-Z0-9+&@#\/%?=~_|!:,.;]*[-A-Z0-9+&@#\/%=~_|])/ig
  str = str.replace(reg, "<a href='$1' class='jump' target='_blank'>$1</a>")
  return str
}

可以应对大多数情况,这种情况还是会被识别成一个链接,有使用者可以改进请大佬告知。感谢🙏  例如:https://baidu.com111111https://baidu.com  

 

转载请带链接:https://www.cnblogs.com/webgyx/p/14392293.html

posted @ 2021-02-09 11:16  Gyx的学习笔记  阅读(651)  评论(0)    收藏  举报