Skip to content

Instantly share code, notes, and snippets.

@Hacksore
Created October 16, 2024 22:35
Show Gist options
  • Select an option

  • Save Hacksore/7c10c1350ad9c71c469d9a6dac096df3 to your computer and use it in GitHub Desktop.

Select an option

Save Hacksore/7c10c1350ad9c71c469d9a6dac096df3 to your computer and use it in GitHub Desktop.
mention.js
function getMentionsFromComment(text) {
// Regex pattern to match mentions in the format @username
const pattern = /@([a-z\d](?:[a-z\d]|-(?=[a-z\d])){0,38})/g;
const mentions = [];
let match;
while ((match = pattern.exec(text)) !== null) {
mentions.push(match[1]);
}
return Array.from(new Set(mentions)).slice(0, 10);
}
getMentionsFromComment("This is a test with two cased names @Hacksore and @SeanAWS vs some @chump")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment