Here's a little demonstration I put together and tested that will show you how to do what you are trying to do...
Notes:
The []'s are a character class and the [1-10] is basically saying match 1-1 and 0 only one time so it will match one instance of 1 or zero only.
To say any number between 1 and ten you do this:
([1-9]|10)
Literally translated it says any number between 1 and 9 or ten.
\1 in the replace string will not work to reference a variables name, it will only add that subpatterns match there as text.
<?php
// define the $Var array
$Var[0]="#one#";
$Var[1]="#two#";
$Var[2]="#three#";
$Var[3]="#four#";
$Var[4]="#five#";
$Var[5]="#six#";
$Var[6]="#seven#";
$Var[7]="#eight#";
$Var[8]="#nine#";
$Var[9]="#ten#";
// define regex patterns for matching
$Regex[0]="/%F1%/iU";
$Regex[1]="/%F2%/iU";
$Regex[2]="/%F3%/iU";
$Regex[3]="/%F4%/iU";
$Regex[4]="/%F5%/iU";
$Regex[5]="/%F6%/iU";
$Regex[6]="/%F7%/iU";
$Regex[7]="/%F8%/iU";
$Regex[8]="/%F9%/iU";
$Regex[9]="/%F10%/iU";
// example string
$string="This %F5% is %F2% some %f3% text %F2% %F10% %F4% with %f1% ten %F6% variables %f7% in %F8% it %F9% %F10% and even a an %F11% with a few % signs %F %F";
// replace %F1-10% in $string with $Var literal
$literal_string=preg_replace("/%F([1-9]|10)%/iU", "\$Var\1", $string);
echo "Replaced with \$Var literal:<br>\n";
echo "---------------------------------------------<br>\n";
echo "\$string=\"".$string."\"<br><br>\n";
echo "\$literal_string=\"".$literal_string."\"<br><br>\n";
// replace %F1-10% with corresponding $Var value
$value_string=preg_replace($Regex, $Var, $string);
echo "Replaced with \$Var value:<br>\n";
echo "---------------------------------------------<br>\n";
echo "\$string=\"".$string."\"<br><br>\n";
echo "\$value_string=\"".$value_string."\"<br><br>\n";
?>
Visit my site to get free software and to search the web with my metacrawler => http://askpete.net