I'm looking to be able to extract a Twitter username from a URL.
E.g: https://twitter.com/jack => jack
I found this Regex to be helpful.
if (preg_match("/^https?:\/\/(www\.)?twitter\.com\/(#!\/)?(?<name>[^\/]+)(\/\w+)*$/", $url, $regs)) {
return $regs['name'];
}
It doesn't seem to work when twitter URL contains query parameters.
For example = https://twitter.com/jack?lang=en
returns jack?lang=en
Any idea how to improve the regex to prevent this ?