preg_replace:制作正则表达式

I know there are a lot of questions with the same problem. I read them but I couldn't fix my code.

<?
$tabla = "<table>
<tr>
<td>
<a class='texto'>$ 2,123.01</a>
</td>
<td>
asddasdsad$,.$$$
</td>
</tr>
</table>";
echo preg_replace("<a class='texto'>\$ ([0-9]*),([0-9]*).([0-9]*)</a>", "<a class='texto'>$0$1,$2</a>", $tabla);

?>

PHP Error: Warning: preg_replace() [function.preg-replace]: Unknown modifier '$'

I would like to get:

<?
<table>
<tr>
<td>
<a class='texto'>2123,01</a>
</td>
<td>
asddasdsad$,.$$$
</td>
</tr>
</table>
?>

I tried & tested my regular expression here http://regexpal.com/ and worked. But I have somthing worong in preg_replace.

You have three mistakes:

  1. \$ inside the double quotes means just $ which is treated by regex as match to end-of-line
  2. You forgot pattern delimiters
  3. $0 refers to the whole string. Expressions in parenthesis are referred to as $1, $2, etc.

echo preg_replace("|<a class='texto'>\\\$ ([0-9]*),([0-9]*).([0-9]*)</a>|", "<a class='texto'>$1$2,$3</a>", $tabla);

Regular expressions need delimiters around the actual expression

<a class='texto'>\$ ([0-9]*),([0-9]*).([0-9]*)</a>

would need to be like:

/<a class='texto'>\$ ([0-9]*),([0-9]*).([0-9]*)<\/a>/

and escape any other / that might be in the expression

or use a different delimiter that doesnt occur in your expression

#<a class='texto'>\$ ([0-9]*),([0-9]*).([0-9]*)</a>#

List of acceptable delimiters