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?