I have been having difficulty extracting specific characters from a string using preg_replace()
. All the strings are the consistent as displayed below with the two examples.
I'm trying to extract the quantity integer, ie. for the first example I would get 200
and the second I would get 50
.
Example Strings
$string = 'Sunscreen 25g (200 Quantity)';
$string = 'Lubricant 100ml (50 Quantity)';
Regex Code
$product = preg_replace('/(Sunscreen|Lubricant)/i', '', $string);
followed by:
$product = preg_replace('/(\(d*.Quantity\))/i', '$0', $product)
Expected Result
From the first string: int(200)
Second string: int(50)
Any help would be appreciated. I cannot get the numbers just before "Quantity" and after the "(".