djs120
asked on
Regular Expression needed in PHP for matching all but last numbers and comma in a variable
I am working in PHP and using preg_match to try to retrieve the following.
$line = " Liatris spicata `Floristan Violet' DND 1 4,111" (yes, there are multiple spaces in there).
Essentially I need to pull out two different variables from this $line: $product, and $quantity, which should be as follows:
$product = "Liatris spicata `Floristan Violet' DND 1" (notice I stripped spaces before and after)
$quantity = "4,111" (I basically want to do a search starting from the last character of the line, moving left until the first SPACE I find, but I DO want to include commas, since this is a quantity variable)
Any help please? Thanks so much.
$line = " Liatris spicata `Floristan Violet' DND 1 4,111" (yes, there are multiple spaces in there).
Essentially I need to pull out two different variables from this $line: $product, and $quantity, which should be as follows:
$product = "Liatris spicata `Floristan Violet' DND 1" (notice I stripped spaces before and after)
$quantity = "4,111" (I basically want to do a search starting from the last character of the line, moving left until the first SPACE I find, but I DO want to include commas, since this is a quantity variable)
Any help please? Thanks so much.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Thanks Diablo. That's exactly what I was looking for and it worked perfectly with my script on all the data I am testing it with. Thanks for responding so quickly.
no problem :)
|)iablo
|)iablo
echo "Product: [".$product."]<br>\n";
echo "Quantity: [".$quantity."]\n";
Note: i added the square brackets to demonstrate the stripped spaces