I have a string which may contain a pattern like:
LINK([anchor text],[link])
What I would like to do is transform this expression into a HTML link:
<a href="link">anchor text</a>
At the moment, I'm performing the replacement with the following PHP snippet:
$string = 'LINK( some anchor text , http://mydomain.com )';
$search = '/LINK\s*\(\s*(.+),\s*([^\s]+)\s*\)/';
$replace = '<a href="$2">$1</a>';
preg_replace($search, $replace, $string);
The problem I'm facing are the spaces after the anchor text. Fortunately, in HTML multiple spaces are interpreted as a single space, but in this example I would however show a link with a (underlined) annoying space. Is there any way to trim this anchor text? I can't treat it as the "link" substring, since it may contain spaces.