Skip to content

Instantly share code, notes, and snippets.

@csellis
Created July 22, 2021 10:55
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save csellis/1b1f9ac512466f87d9aacee23b3689c5 to your computer and use it in GitHub Desktop.
Save csellis/1b1f9ac512466f87d9aacee23b3689c5 to your computer and use it in GitHub Desktop.
Regex to get the Twitter Handle from a given URL
// 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