正则表达式获取pastebin.com的ID


Regex to get ID of pastebin.com

我需要得到一个pastebin链接的ID部分,

设置为http://pastebin.com/{id},我使用了很多不同的正则表达式我还在php中使用preg_match

preg_match("~http://pastebin.com/([0-9a-zA-Z]+)~", $url, $match);
print_r($match);

$url = "http://pastebin.com/a65d46";
$parsed = parse_url($url);
echo trim($parsed['path'])." is ID you needed";

不使用regex,而是使用parse_url来提取路径

regex对于这个是多余的。

$url = "http://pastebin.com/Ugj1eqCN"
$pos = strpos($url,"pastebin.com/");
echo substr($url,$pos+13);