#1
  1. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    May 2009
    Posts
    60
    Rep Power
    7

    Parsing links from a web page [Was: Simple regex help]


    Hi
    I am trying to parse links from a web page and need some help with the following regex
    PHP Code:
    $regex '<a href="/watch?v=(.*?)" class=.*</a>';
    preg_match_all($regex$page$links); 
    $page contains the page contents and has this line for sure
    <a href="/watch?v=4*******M" class="don't care whatever is here"</a>

    i need $links[1] = 4*******M

    Thanks a lot for your help. i spent too much time figuring this out
  2. #2
  3. Did you steal it?
    Devshed Supreme Being (6500+ posts)

    Join Date
    Mar 2007
    Location
    Washington, USA
    Posts
    14,007
    Rep Power
    9398
    You can probably get away with just looking for that one URL.
    Code:
    /(?<=href="/watch\?v=)4(?:.+?)M(?=")/

IMN logo majestic logo threadwatch logo seochat tools logo