找到字符串中的最后一个超链接[关闭]

I would like to find the last hyperlink in a string. The hyperlink may begin with one of the following:

http://

https://

market://

Is there a regex method in PHP to find this?

Thank you.

You can use this negative lookahead based regex:

~\b(?:https?|market)://\S+?(?!.*?\b(?:https?|market)://)~i
$regex = "/(http|https|market)\:\/\/[a-zA-Z0-9\-\.]+\.[a-zA-Z]{2,3}(\/\S*)?/";

$text = "http://link.com some text in between https://link.com more text in between market://link.com";

if(preg_match_all($regex, $text, $url)) 
{
    echo $url[0][count($url[0])-1]; // Outputs: market://link.com
}