Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>Your regexp matches everything starting with one of those protocols, including a lot of things that cannot possibly be existent URLs, if you relax the protocol part (making it optional with ?) then you'll just be matching almost everything, including the empty string.</p> <p>In other words, it does a great job matching URLs because it matches almost anything starting with <a href="http://,https://,ftp://" rel="nofollow noreferrer">http://,https://,ftp://</a> and so on. Well, it also matches ftp:\\ and ms-help://, but let's ignore that.</p> <p>It may make sense, depending on actual usage, because the other regexp approach of whitelisting valid domains becomes non maintainable quickly enough, but making the protocol part optional does not make sense.</p> <p>An example (with the relaxed protocol part in place):</p> <pre><code>&gt;&gt;&gt; r = re.compile('(((https?|ftp|gopher|telnet|file|notes|ms-help):((//)|(\\\\))+)?[\w\d:#@%/;$()~_?\+-=\\\.&amp;]*)') &gt;&gt;&gt; r.search('oompaloompa_is_not_an_ur%&amp;%%l').groups()[0] 'oompaloompa_is_not_an_ur%&amp;%%l' #Matches! &gt;&gt;&gt; r.search('oompaloompa_isdfjakojfsdi.sdnioknfsdjknfsdjk.fsdnjkfnsdjknfsdjk').groups()[0] 'oompaloompa_isdfjakojfsdi.sdnioknfsdjknfsdjk.fsdnjkfnsdjknfsdjk' #Matches! &gt;&gt;&gt; </code></pre> <p>Given your edit I suggest you either make the user select what is he adding, adding an enum column, or create a simpler regex that'll check for at least a dot, besides the valid characters and maybe some common domains.</p> <p>A third alternative which will be <strong>VERY SLOW</strong> and only to be used when URL validation is <strong>REALLY REALLY IMPORTANT</strong> is actually accessing the URL and do a HEAD request on it, if you get a host not found or an error you know it's not valid. For emails you could try and see if the MX host exists and has port 25 open. If both fails, it'll be plain text. (I'm not suggesting this either)</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload