Skip to content

Instantly share code, notes, and snippets.

@Lwdthe1
Last active January 15, 2018 03:12
Show Gist options
  • Save Lwdthe1/ede182dea8c8a397b12c122c97b70e12 to your computer and use it in GitHub Desktop.
Save Lwdthe1/ede182dea8c8a397b12c122c97b70e12 to your computer and use it in GitHub Desktop.
A function to extract all mentioned @usernames from a string
function extractAllMentionedUsernames(str) {
var pattern = /\B@[a-z0-9_-]+/gi;
var arr = str.match(pattern) || []
return arr.map((u) => u.replace('@', ''))
}
// if str = '@lwdthe1 are you @lincoln_w_daniel?'
// extractAllMentionedUsernames(str) => ['lwdthe1', 'lincoln_w_daniel']
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment