Search code examples
phpregexrapidshare

Matching Rapidshare links with regex


I want to match a sequence of Rapidshare links on a webpage. The links look like:

http://rapidshare.com/files/326251387/file_name.rar

I wrote this code:

if(preg_match_all('/http:\/\/\rapidshare\.com\/files\/.*?\/.*?/', $links[1], $links))
{
    echo 'Found links.';
} else {
    die('Cannot find links :(');
}

And it retuns Cannot find links :( every time. Please note that I want to return the entire match, so it will bring back every Rapidshare link found on the page in an array.

$links[1] does have a valid string, too.

Any help will be appreciated, cheers.


Solution

  • Looks like you have a stray backslash before rapidshare

    if(preg_match_all('/http:\/\/\rapidshare\.com\/files\/.*?\/.*?/', $links[1], $links))
    

    Should be

    if(preg_match_all('/http:\/\/rapidshare\.com\/files\/.*?\/[^\s"']+/', $links[1], $links))
    

    (\r is a carriage return character)