Simple Regex Question: Just fetch some numbers out of a string.

Discussion in 'PHP' started by Kellerkind, Mar 19, 2010.

  1. #1
    It is probably dead simple but I wasn't able to find the solution. I have to rewrite some topics in a database and for this I have to cut a number out of it. This is what I tried to get the "453:":

    
        preg_match('[0-9:]', "Status Update 453: News that might disturb", $matches);
        $result = $matches[1];
    echo $result;
    
    PHP:
    I have a program called regexbuddy and it shows that the regex should work but it doesnt... any help would be fantastic!
     
    Kellerkind, Mar 19, 2010 IP
  2. danx10

    danx10 Peon

    Messages:
    1,179
    Likes Received:
    44
    Best Answers:
    2
    Trophy Points:
    0
    #2
    <?php
    
    preg_match('/([0-9:]{4})/', "Status Update 453: News that might disturb", $matches);
    $result = $matches[0];
    echo $result;
    
    ?>
    PHP:
    You have to add delimiters, to the start and end of the expression.
     
    danx10, Mar 19, 2010 IP
  3. guardian999

    guardian999 Well-Known Member

    Messages:
    376
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    103
    #3
    add delimiters, it's should work.
     
    guardian999, Mar 19, 2010 IP
  4. Kellerkind

    Kellerkind Active Member

    Messages:
    160
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    53
    #4
    thanks a lot guys! :)
     
    Kellerkind, Mar 19, 2010 IP