Note that there are some explanatory texts on larger screens.

plurals
  1. POThis regex matches and shouldn't. Why is it?
    text
    copied!<p>This regex:</p> <blockquote> ^((https?|ftp)\:(\/\/)|(file\:\/{2,3}))?(((25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.){3} (25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?))|(((([a-zA-Z0-9]+)(\.)?)+?)(\.)([a-z]{2} |com|org|net|gov|mil|biz|info|mobi|name|aero|jobs|museum))([a-zA-Z0-9\?\=\&\%\/]*)?$ </blockquote> <p>Formatted for readability:</p> <pre><code>^( # Begin regex / begin address clause (https?|ftp)\:(\/\/)|(file\:\/{2,3}))? # protocol ( # container for two address formats, more to come later ((25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.){3} (25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?) # match IP addresses )|( # delimiter for address formats ((([a-zA-Z0-9]+)(\.)?)+?) # match domains and any number of subdomains (\.) #dot for .com ([a-z]{2}|com|org|net|gov|mil|biz|info|mobi|name|aero|jobs|museum) #TLD clause ) # end address clause ([a-zA-Z0-9\?\=\&amp;\%\/]*)? # querystring support, will pretty this up later $ </code></pre> <p>is matching:</p> <blockquote>www.google</blockquote> <p>and shouldn't be. This is one of my "fail" test cases. I have declared the TLD portion of the URL to be mandatory when matching on alpha instead of on IP, and "google" doesn't fit into the "[a-z]{2}" clause.</p> <p>Keep in mind I will fix the following issues seperately - this question is about why it matches www.google and shouldn't.</p> <ul> <li>Querystring needs to support proper formats only, currently accepts any combination of querystring characters</li> <li>Several protocols not supported, though the scope of my requirements may not include them</li> <li>uncommon TLDs with 3 characters not included</li> <li>Probably matches <a href="http://www.google..com" rel="nofollow noreferrer">http://www.google..com</a> - will check for consecutive dots</li> <li>Doesn't support decimal IP address formats</li> </ul> <p><strong>What's wrong with my regex?</strong></p> <p>edit: See also a previous problem with an earlier version of this regex on a different test case: <a href="https://stackoverflow.com/questions/1622446/how-can-i-make-this-regex-match-correctly">How can I make this regex match correctly?</a></p> <p><br /><br /> edit2: Fixed - The corrected regex (as asked) is:</p> <blockquote> ^((https?|ftp)\:(\/\/)|(file\:\/{2,3}))?(((25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.){3} (25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?))|(((([a-zA-Z0-9]+)(\.)?)+?)(\.)([a-z]{2}|com|org|net|gov|mil|biz|info|mobi|name|aero|jobs|museum))([\/][\/a-zA-Z0-9\.]*)*?([\/]?[\?][a-zA-Z0-9\=\&\%\/]*)?$ </blockquote>
 

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