Created
July 22, 2021 10:55
-
-
Save csellis/1b1f9ac512466f87d9aacee23b3689c5 to your computer and use it in GitHub Desktop.
Regex to get the Twitter Handle from a given URL
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Matches patterns: | |
// https://twitter.com/Adobe | |
// Thank you Jamie | |
// https://www.jvt.me/posts/2020/02/08/regex-twitter-profile-url/ | |
export function getTwitterHandle(string) { | |
let regex = /(https:\/\/twitter.com\/(?![a-zA-Z0-9_]+\/)([a-zA-Z0-9_]+))/; | |
return regex.exec(string)[2]; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment