Javascript regex to parse urls without protocol?

I would do something like this: String.prototype. Linkify = function () { return this. Replace(/((?:ht|f)tp:\/\/)?(^:\/\s+\w+\.(?:com|net|org))/gi, function (_, protocol, rest) { var url = (protocol || "") + rest return '' + url + '' }) } (I fixed a couple of other problems with your code: you were missing a return and you were matching the domain name period using .

Rather than \..) And I assume I don’t need to point out how poorly this will match URL:s in general, due to a number of problems with your pattern.

– Tom Fobear Sep 26 at 20:07 1 The parameters are simply $&, $1, $2.My idea of a good way to match URLs in general is outside the scope of this question, since it is actually a pretty hard problem. To put it simply, though, I would start with a complete list of all TLDs, and then match stuff ending in a TLD and having various fluff on either side (that’s easier once you realize that you have to start from the TLD). – Daniel Brockman Sep 26 at 20:13.

If you don't actually need to match FTP URLs, you can just assume the "" section of the link. This regex does that, while allowing you to also use https. This.

Replace(/(http(s)? :\/\/)?((^:\/\s+)\.(com|net|org))/gi, 'http$2://$3') I'm not sure what your use case is, but I'd like to note this regex will fail on the following urls: google.com/spam" rel="nofollow">google.com/spam = google.com/spam" rel="nofollow">google.com/spam google.ca = no match This is because you're using few hardcoded tlds (com, net, org), and aren't matching any characters after the domain.

Clever solution to making sure to grab https as appropriate. – Asmor Sep 26 at 19:21.

I cant really gove you an answer,but what I can give you is a way to a solution, that is you have to find the anglde that you relate to or peaks your interest. A good paper is one that people get drawn into because it reaches them ln some way.As for me WW11 to me, I think of the holocaust and the effect it had on the survivors, their families and those who stood by and did nothing until it was too late.

Related Questions