Discord AutoMod regex examples you can copy

By Better Tickets Team · Updated

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.

LimitValue
Regex patterns per rule10
Characters per pattern260
Plain keywords per rule1,000, up to 60 characters each
Allow list entries100
Custom keyword rules per server6
Regex flavorRust

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:

KeywordMatches
catthe whole word "cat" only
cat*words starting with "cat": catch, catapult
*catwords 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.

text
(?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.

text
https?://\S+

Useful in channels where links aren't allowed at all.

text
\[[^\]]+\]\(https?://[^)]+\)

Catches [text](https://example.com) links, which scammers use to hide where a link goes.

"Free Nitro" scams

text
(?i)free\s*nitro|nitro\s*for\s*free|claim\s*(your\s*)?nitro

Spaced-out or punctuated words

text
(?i)s[\W_]*p[\W_]*a[\W_]*m

Matches "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

text
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

text
[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

text
[\x{0300}-\x{036F}]{4,}

Matches four or more stacked combining marks, the "glitchy" text that overflows lines.

Phone numbers

text
\+?\d[\d\s().-]{8,}\d

Email addresses

text
[\w.+-]+@[\w-]+\.[a-z]{2,}

Test before you turn it on

A pattern that's too broad blocks ordinary messages. Before saving:

  1. 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 the i flag there instead, and write \x{0300} as ̀.
  2. Start the AutoMod rule with send an alert only, and watch what it flags for a day.
  3. 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.