This question already has an answer here:
I referred this question - Capture group reference + numeral
I tried with both the options provided there. Here is example code using ECMAScript expression (I guess I need to use this, correct me if I am wrong) -
$string = "box.last_rollout_revision = dummy";
$regex = "/(box\.last_rollout_revision[\s]*=[\s]*)[a-z0-9-_]*([
]*)/";
$test = "234";
$replacementPattern = "$1".$test."$2";
echo preg_replace($regex,$replacementPattern,$string);
Expected output
box.last_rollout_revision = 234
Actual getting
34
P.S. I am trying to replace value against a key in a config file which has several other key-value pairs. I think regex will make it easier in this case. Correct me if I am wrong.
</div>