title: How do you validate a URL with a regular expression in Python?
body: <p>I'm building an app on Google App Engine. I'm incredibly new to Python and have been beating my head against the following problem for the past 3 days.</p>
  
  <p>I have a class to represent an RSS Feed and in this class I have a method called setUrl. Input to this method is a URL. </p>
  
  <p>I'm trying to use the re python module to validate off of the RFC 3986 Reg-ex (<a href="http://www.ietf.org/rfc/rfc3986.txt" rel="noreferrer">http://www.ietf.org/rfc/rfc3986.txt</a>)</p>
  
  <p>Below is a snipped which <em>should</em> work? </p>
  
  <pre><code>p = re.compile('^(([^:/?#]+):)?(//([^/?#]*))?([^?#]*)(\?([^#]*))?(#(.*))?')
  m = p.match(url)
  if m:
    self.url = url
    return url
  </code></pre>