I have a user input string with Stack Overflow style links within the string like this:
The input string [foo](http://foo.com) with a link.
and I need to transform the string to include anchor tags like this:
The input string <a href="http://foo.com">foo</a> with a link.
So far, I've got (referenced from: PHP: Best way to extract text within parenthesis?):
$text = 'ignore everything except this (text)';
preg_match('#\((.*?)\)#', $text, $match);
print $match[1];
But I need to find a way to match both the element within parentheses and the element within brackets. And finally, replace the entire matched section with a the correctly formatted anchor tag.
Does anyone know the correct regex syntax to match [foo](http://foo.com) and further how to extract "foo" and "http://foo.com"?