I have set of static string set with different integer values. I am trying to get only the part I need using preg_replace
. But the thing is whenever I get the number, it also returns the part after that aswell.
Example strings;
$str = "Increase weather temp by up to 10.";
$str2 = "Increase weather temp by up to 10abc 123 def.";
$str3 = "Increase weather temp by up to 10 12 14.";
Desired output for examples above;
10
My code;
preg_replace('/^Increase weather temp by up to (\d+)/', '$1', $str)
I also tried ~
but it didnt help me to solve the issue aswell. Whenever I test this regex through testers, it works fine;
Is there any part I am missing? Thanks in advance.