Last active
January 15, 2018 03:12
-
-
Save Lwdthe1/ede182dea8c8a397b12c122c97b70e12 to your computer and use it in GitHub Desktop.
A function to extract all mentioned @usernames from a string
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
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