title: URL-BBCode Regex
body: <p>I'm currently trying to get an URL from a BBCode. There are four possibilities for it, and that's my current problem:</p>
  
  <pre><code>[url]http://stackoverflow.com/[/url]
  [url='http://stackoverflow.com/']http://stackoverflow.com/[/url]
  [url="http://stackoverflow.com/"]http://stackoverflow.com/[/url]
  [url=http://stackoverflow.com/]http://stackoverflow.com/[/url]
  </code></pre>
  
  <p>I need both. This is, what i have so far:</p>
  
  <pre><code>/\[url(?:\=\'([^\'"]+)\')?](.+?)\[\/url]/i
  </code></pre>
  
  <p>But that does just work with case 1 &amp; 2.</p>
  
  <p>EDIT:</p>
  
  <p>This works better:</p>
  
  <pre><code>/\[url(?:\=(?:[\"|'])?(.*)(?:[^[]+)?)?\](.*)\[\/url\]/i
  </code></pre>
  
  <p>But still not perfect.</p>
  
  <p>EDIT:</p>
  
  <p>I guess, i got it. It may need some optimization, but it seems to work:</p>
  
  <pre><code>/\[url(?:\=("|\'|)?(.*)?\1)?\](.*)\[\/url\]/i
  </code></pre>
  
  <p>See <a href="http://regexp-tester.mediacix.de/t535" rel="nofollow">regexp-tester</a></p>