How To Use Regex To Truncate A String In Yahoo Pipes?

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

  1. #1
    Hi all,

    I'm using Yahoo Pipes to mashup an RSS feed, but I'm not really familiar with Regex.

    I need a regex expression to get rid of everything after the price (which will always change)

    Here's an example:

    325 11 1 $120.00 <span class="e">each</span><a rel="nofollow" target="_blank" href="http://www.iwantseasonstickets.com/britney-spears-tickets/britney-spears-vancouver-general-motors-place-canada-hockey-place-4-8-2009-764674/?id=166175013"</a>


    All I want to end up with is:
    325 11 1 $120.00

    Can anyone tell me how to do thisÉ Thanks!!
     
    roadrunner12, Jan 19, 2009 IP
  2. Danltn

    Danltn Well-Known Member

    Messages:
    679
    Likes Received:
    36
    Best Answers:
    0
    Trophy Points:
    120
    #2
    <?php
    
    $string = '325 11 1 $120.00 <span class="e">each</span><a rel="nofollow" target="_blank" href="http://www.iwantseasonstickets.com/britney-spears-tickets/britney-spears-vancouver-general-motors-place-canada-hockey-place-4-8-2009-764674/?id=166175013"</a>';
    
    $new_string = trim(substr($string, 0, strpos($string, ' <span class="e">')));
    
    echo $new_string;
    
    PHP:
     
    Danltn, Jan 20, 2009 IP
  3. Kaizoku

    Kaizoku Well-Known Member

    Messages:
    1,261
    Likes Received:
    20
    Best Answers:
    1
    Trophy Points:
    105
    #3
    if you really need regex.

    
    preg_match("/^[^<]+?/", $string, $matches);
    $matches = rtrim($matches[0]);
    
    PHP:
     
    Kaizoku, Jan 21, 2009 IP