php regex to split invoice line item description

Posted by user1053700 on Stack Overflow See other posts from Stack Overflow or by user1053700
Published on 2012-11-30T20:32:00Z Indexed on 2012/12/01 17:04 UTC
Read the original article Hit count: 167

Filed under:
|
|

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?

© Stack Overflow or respective owner

Related posts about php

Related posts about regex