title: Replace URL with a link using regex in python
body: <p>how do I convert some text to a link? Back in PHP, I used this piece of code that worked well for my purpose:</p>
  
  <pre><code>            $text = preg_replace("#(^|[\n ])(([\w]+?://[\w\#$%&amp;~.\-;:=,?@\[\]+]*)(/[\w\#$%&amp;~/.\-;:=,?@\[\]+]*)?)#is", "\\1&lt;a href=\"\\2\" target=\"_blank\"&gt;\\3&lt;/a&gt;", $text);
              $text = preg_replace("#(^|[\n ])(((www|ftp)\.[\w\#$%&amp;~.\-;:=,?@\[\]+]*)(/[\w\#$%&amp;~/.\-;:=,?@\[\]+]*)?)#is", "\\1&lt;a href=\"http://\\2\" target=\"_blank\"&gt;\\3&lt;/a&gt;", $text);
  </code></pre>
  
  <p>I tried around in Python, but was unable to get it to work.. Would be very nice if someone could translate this to Python :)..</p>