Regex: Extract Tweet Username and ID From URL
<p>I'm trying to fetch the tweet URL, if found, in a message with this regex <code>#^https?://twitter\.com/(?:\#!/)?(\w+)/status(es)?/(\d+)$#is</code></p>

<p>But it seems my regex is not correct to fetch for the tweet URL. Below is my full code</p>

<pre><code>function gettweet($string)
{
    $regex = '#^https?://twitter\.com/(?:\#!/)?(\w+)/status(es)?/(\d+)$#is';
    $string = preg_replace_callback($regex, function($matches) {
        $user = $matches[2];
        $statusid = $matches[3];
        $url = "https://twitter.com/$user/status/$statusid";
        $urlen = urlencode($url);
        $getcon = file_get_contents("https://publish.twitter.com/oembed?url=$urlen");
        $con = json_decode($getcon, true);
        $tweet_html = $con["html"];
        return $tweet_html;
    }, $string);
    return $string;
}

$message="This is absolutely trending can you also see it here https://twitter.com/itslifeme/status/765268556133064704 i like it";
$mes=gettweet($message);
echo $mes;
</code></pre>