从URL获取Instagram用户名 - 忽略带有正则表达式的句点

I've been able to retrieve the Username from an instagram profile URL with regex, however it stops once it reaches a full-stop

.

Full URL: https://www.instagram.com/username.test.uk/

The output from my regex: https://www.instagram.com/username

My regex and output:

// Regex for verifying an instagram URL
$regex = '/(?:(?:http|https):\/\/)?(?:www.)?(?:instagram.com|instagr.am)\/([A-Za-z0-9-_]+)/im';

// Verify valid Instagram URL
if ( preg_match( $regex, $instagram_url, $matches ) ) {

    $instagram_username = $matches[1];

    var_dump($instagram_username);

The var dump produces: username

Any obvious changes needed to my regex to exclude . in the username section?

So it stops because your match for the username doesn't include the ..

/(?:(?:http|https):\/\/)?(?:www.)?(?:instagram.com|instagr.am)\/([A-Za-z0-9-_]+)/im

This should probably include \. within ([A-Za-z0-9-_]+).

/(?:(?:http|https):\/\/)?(?:www.)?(?:instagram.com|instagr.am)\/([A-Za-z0-9-_\.]+)/im

This will capture all alpha-numerics, underscores and dots.