It seems this forum likes to strip out some backslashes. I included extra so they would appear correctly. I assume this is what you meant in your post.
$content = preg_replace("/<a href=\"(.*)\">(.*)<\\/a>/i", "\\\\2 [\\\\1]", $content);
This regex has a few issues. It only works for links which do not span lines, it will only work if there is no more then one link per line in the source code. It only finds links in the form <a href="http://"></a>. (If there's an onmouseover, or a style or id, or anything else in the a tag, then it doesn't catch it.) It doesn't find links where the quotes were ommitted.
Here's a more complicated regex:
$content = preg_replace('#<a[^>]*?href="?(.*?)("[^>]*|)>(.*?)</a>#is', '\\3 [\\1]', $content);
And an explanation.
' - Used single quotes to avoid having to escape some things
- Pattern delimiter
<a - Pattern starts with "<a"
[>]? - Match one or more non ">" characters in a non-greedy fashion
href= - Match "href="
"? - Match a single optional (0 or 1) double quote character
(.?) - Match any number of characters in a non-greedy fashion and store in first backreference
("[>]|)> - Match a double quote followed by any number of non ">" characters OR nothing followed by a ">"
(.?) - Match any number of characters in a non-greedy fashion and store in third backreference
</a> - Match the ending link tag
#is - End pattern, ignore case flag and treat as single line flag.
The manual explains "greedy" and "non-greedy" like this:
By default, the quantifiers are "greedy", that is, they match as much as possible (up to the maximum number of permitted times), without causing the rest of the pattern to fail. The classic example of where this gives problems is in trying to match comments in C programs. These appear between the sequences / and / and within the sequence, individual and / characters may appear. An attempt to match C comments by applying the pattern /*.*/ to the string / first command / not comment / second comment / fails, because it matches the entire string due to the greediness of the .* item.
However, if a quantifier is followed by a question mark, then it ceases to be greedy, and instead matches the minimum number of times possible, so the pattern /*.*?*/ does the right thing with the C comments. The meaning of the various quantifiers is not otherwise changed, just the preferred number of matches.