some easy help with regex?

Discussion in 'PHP' started by roadrunner12, Jan 19, 2009.

  1. #1
    Hey guys,

    I need a regex to remove everything before the price:

    314 15 Up to 4 $142.00

    Keep in mind that whatever comes before the price won't be the same thing everytime.

    Can anyone help? Thanks!
     
    roadrunner12, Jan 19, 2009 IP
  2. lp1051

    lp1051 Well-Known Member

    Messages:
    163
    Likes Received:
    7
    Best Answers:
    0
    Trophy Points:
    108
    #2
    Hey,
    can be before price another '$' sign?? If not, you can use e.g.
    $string="314 15 Up to 4 $142.00";
    preg_match('/^[^$]+(\$\d+\.\d+)$/', $string, $price);
    then you have price in $price[1]. It also counts, that price format is always '$numbers.numbers'
    Hope it helps
     
    lp1051, Jan 20, 2009 IP
  3. WPGLamour

    WPGLamour Active Member

    Messages:
    30
    Likes Received:
    2
    Best Answers:
    0
    Trophy Points:
    95
    #3
    You can also use:
    $price = "314 15 Up to 4 $142.00";
    $price = explode("$", $price);
    $price[0] will echo 314 15 Up to 4
    and $price[1] will echo 142.00
     
    WPGLamour, Jan 20, 2009 IP