Regex Help

Discussion in 'Programming' started by Christian Little, Mar 11, 2008.

  1. #1
    I'm working on a script to pull data from dmoz.org. Here is the string I'm trying to isolate:

    <b>Open Directory Sites</b></font> (1-20 of 395)

    The number in red is what I have to assign to $1 for it to work with my script ($1 is used in other calculations, so it has to be assigned to that).

    I've tried these two patterns and it's not matching for either:

    /Open Directory Sites<\/b><\/font> [.*] of (.*)/Us
    /Open Directory Sites<\/b><\/font> \([0-9]-[0-9] of (.*)\)/Us

    Any suggestions? Remember, the number in red that I'm trying to match has to be $1.
     
    Christian Little, Mar 11, 2008 IP
  2. Robert T

    Robert T Peon

    Messages:
    105
    Likes Received:
    3
    Best Answers:
    0
    Trophy Points:
    0
    #2
    $a = "<b>Open Directory Sites</b></font> (1-20 of 395)";
    preg_match('@Open Directory Sites</b></font> \(.* of (.*?)\)@',$a, $b);
    print_r($b);
     
    Robert T, Mar 11, 2008 IP
  3. TechnoGeek

    TechnoGeek Peon

    Messages:
    258
    Likes Received:
    6
    Best Answers:
    0
    Trophy Points:
    0
    #3
    Did you try

    /\s\(\d+)\)$/

    ?
     
    TechnoGeek, Mar 11, 2008 IP