title: Postgres regex matching - match a character OR nothing
body: <p>I am trying to get the domain name in Postgres using a regex.</p>
  
  <p>When I do:</p>
  
  <pre><code>select substring('http://yahoo.com' from 'http://(.+?)/|');
  </code></pre>
  
  <p>it returns the empty string.
  I want it to return <a href="http://yahoo.com" rel="nofollow">http://yahoo.com</a></p>
  
  <p>It works if I do the below, but not all urls end with a trailing slash.</p>
  
  <pre><code>select substring('http://yahoo.com/' from 'http://(.+?)/|');
  </code></pre>