I'm currently trying to get an URL from a BBCode. There are four possibilities for it, and that's my current problem:
[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]
I need both. This is, what i have so far:
/\[url(?:\=\'([^\'"]+)\')?](.+?)\[\/url]/i
But that does just work with case 1 & 2.
EDIT:
This works better:
/\[url(?:\=(?:[\"|'])?(.*)(?:[^[]+)?)?\](.*)\[\/url\]/i
But still not perfect.
EDIT:
I guess, i got it. It may need some optimization, but it seems to work:
/\[url(?:\=("|\'|)?(.*)?\1)?\](.*)\[\/url\]/i
See regexp-tester