Skip to content

Instantly share code, notes, and snippets.

@LapisOnTheMoon
Forked from anishshobithps/regex.js
Last active August 23, 2023 19:48
Show Gist options
  • Save LapisOnTheMoon/dbc40c3a15f9a7192daa9bec283d1126 to your computer and use it in GitHub Desktop.
Save LapisOnTheMoon/dbc40c3a15f9a7192daa9bec283d1126 to your computer and use it in GitHub Desktop.
Various regex for Discord
module.exports = {
mentions: {
userOrMember: /^(?:<@!?)?(\d{17,19})>?$/,
channel: /^(?:<#)?(\d{17,19})>?$/,
role: /^(?:<@&)?(\d{17,19})>?$/,
snowflake: /^(\d{17,19})$/,
},
misc: {
emoji: /^(?:<a?:\w{2,32}:)?(\d{17,19})>?$/,
username: /.{2,32}/,
invite: /(http(s)?:\/\/)?(www\.)?(discord\.(gg|li|me|io)|discordapp\.com\/invite|invite\.gg)\/.\w+/,
discriminator: /(#)\d{4}/,
tag: /.{2,32}(#)\d{4}/,
token: /[\w]{24}\.[\w]{6}\.[\w-_]{27}/,
},
};
/**
You can find the details how these regex works on https://regex101.com/
If you have issues with these and if you know better way to do it please drop a comment :D
**/
@Samathingamajig
Copy link

I think this can benefit by including a regex for what discord itself considers a link (what makes it decide to convert a string to a hyperlink)

@kvba0000
Copy link

Thanks mate, i'll help me with some of my projects.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment