用PHP中的正则表达式从页面中提取网址[复制]

This question is an exact duplicate of:

How would I make a regex to extract urls from a page where I am matching to a center part of a url

For example my urls to match would be something like:

http://m2.imageserver.net/media/thumb/66177422433.jpg http://m4.imageserver.net/media/thumb/21717623342.jpg http://m1.imageserver.net/media/thumb/12327722433.jpg

And I want to match by just the imageserver.net/media section of the url as the sub domain may change.

</div>

Your regex would be http://[a-zA-Z0-9]+.imageserver.net+[a-zA-Z0-9/]+.jpg.

Advice: Before trying out on code, please check using regexpal. It's basically a javascript regex tester.

Update: Adding a delimiter:

$match_pattern = "#http:\/\/[a-zA-Z0-9]+.imageserver.net+[a-zA-Z0-9\/]+.jpg#";
preg_match_all($match_pattern,$string_to_be_matched,$url_array);

I have try this one for you. maybe it can help you though.

$text = "http://m2.imageserver.net/media/thumb/66177422433.jpg";

$text = preg_match("/imageserver.net\/media/", $text, $match);

print_r($match);

If I totally understand your question this might be the answer.

I don't use regex much but I think this might work.

$string = "jjYy5nhttp://m2.imageserver.net/media/thumb/66177422433.jpgru56rtjr";

    $pattern = "/http:\/\/[^0-9a-zA-Z_ -].imageserver.net\/media\/(.*?).jpg/";
    if (@preg_match_all(${pattern}, ${string}, $matches) ) {
       print $matches['0'];
    }