Something like this (in Java Script): If you really want to know how, or have some uncertainties, just write below in comments. So, in order not to mix up some bracket that is not part of the URL, we are capturing the brackets before and after URL as well, and all you have to do after matching is to check if the both brackets exist and remove them. Anything else, and this whole exercise is a sham, because people will just write whatever works for them, or how they like it, and sacrifice "making any sense" in favour of being short ( like I did ).The most Naïve regex I can come up with that matches (and captures) all your pasted examples so far is: I think the sane approach is to extract things that are likely to be URI's, then validate them with something stricter, I'm looking at working out how to use the browsers URI class to validate them =).It is supported by all major programming languages (PHP, Perl, Java Script, Java, . Here you can see URL anathomy (along with good SEO practices), or just search across the web for it.
)/gi; /* (^|\s) : ensure that we are not matching an url embeded in an other string (https? : the http or https schemes (optional) [\w-] (\.[\w-] ) \.?
as the regular expression and match valid URIs and not match all your examples on the »Not match« list. In order to be a rule that works as you intend, you actually do need to implement a full RFC compliant matcher, and a full RFC compliant matcher will "worry about not matching".
As long as you're going that route it's simply the question: What is the shortest regular expression that will not match any of the example strings but still catch all re = /(^|\s)((https? So, in terms of "permit not matching", you need to specify exactly which deviations from RFC are permissible.
Now here comes the fun part, once we’ve matched an URL, we can do with it whatever we like.
I just couldn’t get myself to write this right now, but I will if someone is interested. You should read the appropriate RFCs which contain relevant parts of the grammar.