title: Python - Regex matching urls in page source code
body: <p>I use this pattern to match every url in a given webpage:</p>
  
  <pre><code>import re
  
  source = """
  &lt;p&gt;https://example.com&lt;/p&gt;
  ... some code
  &lt;font color="E80000"&gt;https://example.com&lt;/font&gt;&lt;/a&gt;
  """
  
  urls = re.findall('http[s]?://(?:[a-zA-Z]|[0-9]|[$-_@.&amp;+]|[!*\(\),]|(?:%[0-9a-fA-F][0-9a-fA-F]))+', source)
  </code></pre>
  
  <p>This has worked for me pretty well until now. I found that sometimes it doesn't match the exact url. Like in the example it match as url <code>https://example.com&lt;/p&gt;</code> and <code>https://example.com&lt;/font&gt;&lt;/a&gt;</code> inlcuding the closing tags but I can't figure out what is the problem in the regex. I took this code from another stack question.</p>