I want to find bulletproof RegEx for URLs inside text using JavaScript (I'm replacing urls with <a>
tags), My current was RegEx:
var url_re = /https?:\/\/(?:(?!&[^;]+;)[^\s:"'<>)])+/g;
It was working but didn't match urls with port (like http://localhost:8080
). Does this RegEx will match all urls or I miss something too?
var url_re = /https?:\/\/[^\/\s"'<>]+\/?(?:(?!&[^;]+;)[^\s:"'<>)])+/g;
Or maybe there is shorter/better regex for urls.
You can probably use this regex:
\bhttps?:\/\/(?:(?!&[^;]+;)[^\s"'<>)])+\b
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.