title: Extracting URL link using regular expression re - string matching - Python
body: <p>I've been trying to extract URLs from a text file using re api. any link that starts with http:// , https:// and www.</p>
  
  <p>the file contains texts as well as html source code, html part is easy because i can extract them using BeautifulSoup, but normal text seems to be more challenging.
  I found this online which seems to be the best implementation of URL extraction however it fails on certain tags, specially it can't handle  tags and includes them in the URL.
  any help is appreciated, because I'm not familiar with string matching at all myself</p>
  
  <p>here is the signature</p>
  
  <pre><code>sp1=re.findall("http[s]?://(?:[a-zA-Z]|[0-9]|[$-_@.&amp;+]|[!*\(\),]|(?:%[0-9a-fA-F][0-9a-fA-F]))+", str(STRING))
  sp2=re.findall('www.(?:[a-zA-Z]|[0-9]|[$-_@.&amp;+]|[!*\(\),]|(?:%[0-9a-fA-F][0-9a-fA-F]))+', str(STRING))
  </code></pre>
  
  <p>examples:</p>
  
  <pre><code>http://www.website.com/science/&lt;/span&gt;&lt;/a&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;&lt;div
  www.website.com/library/&lt;/span&gt;&lt;/a&gt;&lt;/span&gt;&lt;/i&gt;&lt;span
  http://awebsite.com/Groups&lt;/a&gt;&lt;div&gt;
  </code></pre>