Test a regular expression against sample text and see every match highlighted as you type, using JavaScript's regex engine.
e.g. "i" (case-insensitive)
Highlighted text shows what the pattern matched.
A regex is a pattern that describes text to match rather than one exact string, which makes it useful for moderation filters such as Better Tickets auto-jail triggers. Those triggers run on the same engine as this tester.
How to use the regex tester
Enter a pattern
Type your regular expression in Pattern, without surrounding slashes.
Set flags
Add flags such as i for case-insensitive matching. The flags are listed below.
Paste test text
Paste a sample message, ideally one you want to match and one you don't.
Read the result
Matches are highlighted live. An invalid pattern shows the error instead.
How regular expressions work
A pattern is built from a small set of building blocks, combined together.
Literal characters
Most characters just match themselves. The pattern cat matches the text cat wherever it appears.
Character classes
A character class matches one character out of a set.
| Syntax | Matches |
|---|---|
[abc] | a, b, or c |
[^abc] | Any character except a, b, or c |
[a-z] | Any lowercase letter |
\d | Any digit ([0-9]) |
\w | Any word character ([A-Za-z0-9_]) |
\s | Any whitespace character |
\D, \W, \S | The negation of \d, \w, \s |
. | Any character except a newline |
Quantifiers
A quantifier says how many times the thing before it can repeat.
| Syntax | Meaning |
|---|---|
* | Zero or more |
+ | One or more |
? | Zero or one (optional) |
{3} | Exactly 3 |
{2,4} | Between 2 and 4 |
{2,} | 2 or more |
Quantifiers are greedy by default: they match as much as possible before backing off. Adding ? after a quantifier (*?, +?) makes it lazy instead, matching as little as possible.
Anchors and boundaries
| Syntax | Meaning |
|---|---|
^ | Start of the string (or line, with the m flag) |
$ | End of the string (or line, with the m flag) |
\b | A word boundary: the edge between a word character and a non-word character |
\B | Not a word boundary |
\bcat\b matches cat as its own word, not the cat inside catalog.
Groups and alternation
Parentheses () group part of a pattern together, so a quantifier can apply to the whole group and so the matched text can be extracted separately. The pipe | inside or around a group means "or": cat|dog matches either cat or dog.
Escaping
Characters like . * + ? ( ) [ ] { } ^ $ | are special to regex. To match one of them literally, put a backslash in front of it: \. matches a literal period, \( matches a literal opening parenthesis.
Flags
Flags go after the pattern and change how the whole match runs.
| Flag | Name | Effect |
|---|---|---|
d | indices | Adds match indices to results |
g | global | Finds all matches instead of stopping at the first |
i | ignoreCase | Case-insensitive matching |
m | multiline | ^/$ match at the start/end of each line, not just the whole string |
s | dotAll | . also matches newlines |
u | unicode | Treats the pattern as a sequence of Unicode code points |
v | unicodeSets | Newer, stricter version of u |
y | sticky | Matches only starting at the current position |
Example patterns
cat|dog|birdSome patterns can run very slowly on certain input, particularly nested repetition like (a+)+b. If a pattern needs to run against arbitrary user-supplied text, test it against a long, unusual input in the tester above before relying on it.
Run your server with Better Tickets
A free Discord bot for support tickets, staff applications, jail and leveling, all set up from one web dashboard.
Frequently asked questions
Which regex engine does this tester use?
Your browser's JavaScript engine. Better Tickets auto-jail triggers run on JavaScript too, so a pattern that behaves here behaves the same way there.
How do I make a pattern case-insensitive?
Add the i flag. free nitro with i matches "Free Nitro", "FREE NITRO" and every mix in between.
How do I match a whole word only?
Wrap it in word boundaries: \bscam\b matches "scam" but not "scamper".
Why does my pattern match too much?
Quantifiers like .* are greedy and grab as much as they can. Make them lazy with ? (.*?), anchor the pattern with ^ and $, or use a narrower class such as \S+ instead of .*.
Can a regex be slow?
Yes. Nested repetition such as (a+)+b can take a very long time on some inputs. Test patterns against long, unusual text before using them on messages from the public.
Related tools and guides
- Auto-jail triggersJail members automatically when a message matches a word list or regex.
- Discord moderation and jail systemsWhen to jail, time out or ban, and how to keep it fair.
- Discord colored text generatorColor and style text with ANSI code blocks.
- Discord embed generatorBuild embeds and copy webhook-ready JSON.