php正则表达式拆分发票行项目描述

I am attempting to split strings like the following:

An item (Item A) which may contain 89798 numbers and letters @ $550.00

4 of Item B @ $420.00

476584 of Item C, with a larger quantity and different currency symbol @ £420.00

into:

array(

    0 => 1

    1 => "some item which may contain 89798 numbers and letters"

    2 => $550.00

);

does that make sense?

I am looking for a regex pattern which will split the quantity, description, and price (including symbol).

the strings will always be:

qty x description @ price+symbol

so i assume the regex would be something like:

`(match a number and only a number) x (get description letters and numbers before the @ symbol) @ (match the currency symbol and price)`

How should I approach this?

preg_match('/^(\d+)\s*x\s(.+)\s@\s*([^@]+)$/', $string, $match);
unset($match[0]);
print_r($match);

If there will always be whitespace around either side of x and @ You can try this:

$pattern = '/\s*(x|@)\s*/';
$array = preg_split($pattern, $input_string);