title: Perl regex substitution for a URL
body: <p>I am trying to use a complex regex to match URLs in a body of text. The aim is to delimit the URLs in the text. </p>
  
  <p>I would like to do something like the below</p>
  
  <pre><code>perl -pe 's/regex/left $1 right/g;' inputfile
  </code></pre>
  
  <p>which will substitute all occurrences of the regex with the matched value surrounded by the words <code>left</code> and <code>right</code> This is just a simplified example to illustrate the point - the real scenario has loads of <code>-e</code> expressions and I am looking to add another for this particular matching purpose. </p>
  
  <p>The regex is whever matches a URL. I realise matching URLs is very difficult and probably impossible to identify all possiblities but a reasonable approximation would be fine. I have found one such approximation at <a href="http://daringfireball.net/2010/07/improved_regex_for_matching_urls" rel="nofollow">http://daringfireball.net/2010/07/improved_regex_for_matching_urls</a>.</p>
  
  <p>I cannot, however, that regex to work in a perl construct like the above. I have tried with different delimiters than <code>/</code> for example <code>~</code> but without success.</p>