Created
October 16, 2024 22:35
-
-
Save Hacksore/7c10c1350ad9c71c469d9a6dac096df3 to your computer and use it in GitHub Desktop.
mention.js
This file contains hidden or 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 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