title: URI Regex: Replace http://, https://, ftp:// with empty string if URL valid
body: <p>I have a simple URL validator. The url validator works as probably every other validator.</p>
  
  <p>Now I want, if the URL passed, take the https://, http:// and remove it for <code>var b</code>.</p>
  
  <p>So what I've done is I made a another Regex which captures https://, http://, ftp:// etc and say if the url passed the long test, get the second test and replace it with empty string.</p>
  
  <p>Here is what I came up with:</p>
  
  <pre><code>$("button").on('click', function () {
     var url = $('#in').val();
  
     var match = /^([a-z][a-z0-9\*\-\.]*):\/\/(?:(?:(?:[\w\.\-\+!$&amp;'\(\)*\+,;=]|%[0-9a-f]{2})+:)*(?:[\w\.\-\+%!$&amp;'\(\)*\+,;=]|%[0-9a-f]{2})+@)?(?:(?:[a-z0-9\-\.]|%[0-9a-f]{2})+|(?:\[(?:[0-9a-f]{0,4}:)*(?:[0-9a-f]{0,4})\]))(?::[0-9]+)?(?:[\/|\?](?:[\w#!:\.\?\+=&amp;@!$'~*,;\/\(\)\[\]\-]|%[0-9a-f]{2})*)?$/;
     var protomatch = /^(https?|ftp):\/\/(.*)/;
  
  
     if (match.test(url)) { // IF VALID
        console.log(url + ' is valid');
  
        // if valid replace http, https, ftp etc with empty
        var b = url.replace(protomatch.test(url), '');
        console.log(b)
  
     } else { // IF INVALID
        console.log('not valid')
     }
  
  });
  </code></pre>
  
  <p>Why this doesn't work?</p>