I've a string which can look something like this:
)250 W (501 PS
20 ps
50 ps
LPG) 246 kW (334 PS
I want to get 501, 20, 50 and 334
respectively.
In other words: The digit
just before PS
OR ps
(case insensitive).
I tired this, but doesn't work for all cases as shown above:
$str = 'LPG) 246 kW (334 PS';
preg_match('/\d+(.*?)PS/',$str, $m);
print_r($m);
How can I change my code to work for every possible string as shown above?
Just use this regex:
/(\d+)\s*ps/i
explanation:
flags: