$re = '/(\[)(\d+)(\].*\')(.+)(\')/m';
$str = ' [1] = 0 \'NumProgPlc\'
[2] = 3 \'PadCode\'
[3] = 2 \'TablePos\'
[4] = 1 \'CurrentTool\'
[5] = 0 \'Loc. Override\'
[10] = .200000 \'PlaceDelay\'
[11] = .300000 \'PickDelay\'
[12] = .150000 \'ChamfersChkDelay\'
[15] = -107.575500 \'xLpos\'
[16] = 398.586304 \'yLpos\'
[17] = 277.373779 \'zLpos\'
[18] = 90.000000 \'RotApproNasAlim\'
[21] = 53 \'PR Offset Tavola\'
[22] = 110 \'PR Sopra Tavola\'
[23] = 267 \'DO Magnete ON\'
[24] = 268 \'DO Magnete OFF\'
[25] = 243 \'DI PresPastTav\'
[26] = 247 \'DI PezNoPrelTav\'
[27] = 1 \'DO Soffio\'
[28] = 111 \'PR Tavola+20\'
[29] = 112 \'PR Tavola\'
[30] = 0 \'_Prelevato\'
[31] = 0 \'_ScartoTav\'
[32] = 0 \'_ScartoCtrlUs\'
[33] = 0 \'_ScambioTav\'
[34] = 0 \'_CaricoTav\'
[35] = 1 \'FlagMemPtoNasAli\'
[36] = 244 \'DO PezPrelTav\'
[37] = 243 \'DO PezScamTav\'
[38] = 242 \'DO PezDepoTav\'
[39] = 132 \'PR Tavola+50\'
[45] = 229 \'DI PezPrelNas\'
[46] = 1 \'OK_PRL\'
[50] = 1 \'PrioritaNas\'
[51] = 0 \'CaricoNas\'
[55] = 0 \'Conveyor2Rot180\'
[200] = 3.216000 \'TC\'
';
$subst = "R\t\2\t\4";
$result = preg_replace($re, $subst, $str);
echo "The result of the substitution is ".$result;
Please keep in mind that these code samples are automatically generated and are not guaranteed to work. If you find any syntax errors, feel free to submit a bug report. For a full regex reference for PHP, please visit: http://php.net/manual/en/ref.pcre.php