Discord's AutoMod accepts regular expressions in custom keyword rules: up to 10 patterns per rule, 260 characters each, written in Rust-flavored regex. That flavor has no lookaheads, lookbehinds or backreferences, which is why patterns copied from other sites often fail. The examples below avoid those features, so you can paste them straight in.
AutoMod regex limits
These come from Discord's developer documentation.
| Limit | Value |
|---|---|
| Regex patterns per rule | 10 |
| Characters per pattern | 260 |
| Plain keywords per rule | 1,000, up to 60 characters each |
| Allow list entries | 100 |
| Custom keyword rules per server | 6 |
| Regex flavor | Rust |
Add patterns in your server's AutoMod settings, in a custom keyword rule's regex section.
Use keywords before regex
Plain keywords are easier to maintain, and wildcards cover most needs:
| Keyword | Matches |
|---|---|
cat | the whole word "cat" only |
cat* | words starting with "cat": catch, catapult |
*cat | words ending with "cat": wildcat |
*cat* | "cat" anywhere: location |
Keywords are case-insensitive. Reach for regex when you need patterns such as links, repeated characters or spaced-out letters.
Copy-ready patterns
Each pattern is under 260 characters and avoids lookarounds and backreferences. (?i) at the start makes it case-insensitive.
Discord invite links
(?i)(discord\.gg|discord(app)?\.com/invite)/[a-z0-9-]+Blocks invites to other servers. Add your own invite code to the rule's allow list.
Any link
https?://\S+Useful in channels where links aren't allowed at all.
Masked links
\[[^\]]+\]\(https?://[^)]+\)Catches [text](https://example.com) links, which scammers use to hide where a link goes.
"Free Nitro" scams
(?i)free\s*nitro|nitro\s*for\s*free|claim\s*(your\s*)?nitroSpaced-out or punctuated words
(?i)s[\W_]*p[\W_]*a[\W_]*mMatches "s p a m", "s.p.a.m" and "s_p_a_m". Swap in the letters of the word you're filtering.
Stretched characters
a{6,}|e{6,}|o{6,}|!{6,}|\?{6,}Rust regex has no backreferences, so (.)\1{5,} won't work. List the characters you care about instead.
Shouting
[A-Z][A-Z\s!?]{24,}Matches 25 or more capital letters, spaces and exclamation marks in a row. Don't add (?i) to this one.
Zalgo text
[\x{0300}-\x{036F}]{4,}Matches four or more stacked combining marks, the "glitchy" text that overflows lines.
Phone numbers
\+?\d[\d\s().-]{8,}\dEmail addresses
[\w.+-]+@[\w-]+\.[a-z]{2,}Test before you turn it on
A pattern that's too broad blocks ordinary messages. Before saving:
- Paste it into the regex tester with a few messages it should catch and a few it shouldn't. The tester uses JavaScript regex, so remove
(?i)and add theiflag there instead, and write\x{0300}as̀. - Start the AutoMod rule with send an alert only, and watch what it flags for a day.
- Then switch on block message, and exempt your staff roles.
Go further than blocking
AutoMod can block a message, alert staff or time a member out. If you'd rather review the member, Better Tickets' auto-jail triggers jail them when a message matches a word list or regex: their roles are removed and a private channel opens with staff. The same patterns work there with the JavaScript changes above. For the role and channel setup behind a jail, see how to make a jail role.
Frequently asked questions
Does Discord AutoMod support regex?
Yes. A custom keyword rule accepts up to 10 regex patterns of up to 260 characters each, alongside up to 1,000 plain keywords. Discord's documentation says only Rust-flavored regex is supported.
Why doesn't my regex work in AutoMod?
The most common cause is using lookaheads, lookbehinds or backreferences. Rust's regex engine doesn't support them, so patterns that work in JavaScript or Python testers can be rejected. Rewrite the pattern without them.
How do I make an AutoMod regex case-insensitive?
Start the pattern with (?i). For example, (?i)free\s*nitro matches "Free Nitro" and "FREE NITRO".
What do the wildcards in AutoMod keywords mean?
An asterisk controls matching: cat* matches words starting with cat, *cat words ending with it, *cat* anywhere in a word, and cat with no asterisk matches only the whole word. Keywords are case-insensitive.
Can I use the same patterns in Better Tickets auto-jail?
Yes, with one change. Better Tickets uses JavaScript regex, so leave out the (?i) prefix and put i in the trigger's flags field instead.