I have a script which does substring replace in large text file. Its working in some case i.e. if new substring is started with numeric character.
Same code is working if new substring is starting with non-numeric number
Working code
$script3 = 'var Title = "Update Notepad++";
var GUID = "f9145f3d-243c-4bec-863f-5696c1d35c64";
var silentParams = "/S";
var optionalParams = " /noupdate";' ;
$packageID2 = 'g9145f3d-243c-4bec-863f-5696c1d35c64' ;
$script4 = preg_replace('/(var GUID = ").*?(")/', "$1$packageID2$2", $script3);
output below:
var Title = "Update Notepad++";
var GUID = "g9145f3d-243c-4bec-863f-5696c1d35c64"; //GUID replaced correctly
var silentParams = "/S";
var optionalParams = " /noupdate";
Not Working code
$script = 'var Title = "Update Google Chrome";
var GUID = "77063f75-fcef-4eaa-a598-fd0d4a8e6f21";
var silentParams = "/S";
var optionalParams = " /business ";' ;
$packageID = '22398ee8-6e2f-4931-943e-5445085adb7f' ;
$script1 = preg_replace('/(var GUID = ").*?(")/', "$1$packageID$2", $script);
Output: script1 is
var Title = "Update Google Chrome";
2398ee8-6e2f-4931-943e-5445085adb7f"; //issue here - GUID removed
var silentParams = "/S";
var optionalParams = " /business ";
Here requirement is to replace the GUID correctly in even if first character of new GUID is numeric ?