What a regex tester does
A regular expression, or regex, is a small pattern language for finding text. \d{4} means “four digits in a row”. [\w.+-]+@ means “one or more word characters, dots, plus signs or hyphens, followed by an @”. Regex is used for search and replace in code editors, form validation, log analysis and data cleanup.
Patterns are easy to get slightly wrong. A tester lets you try a pattern on real sample text and see exactly what it catches before you put it in a script. This one shows matches as you type, lists every capture group and previews a replacement.
How to use the regex tester
- Type your pattern into Regular expression. Leave out the slashes. The tool shows them for you, with the active flags after the closing slash.
- Switch flags on or off with the buttons g, i, m, s, u and y.
- Paste or type sample text into Test text.
- Read the result in Matches. Each match is highlighted and the counter shows how many were found.
- Check Match details and groups for the position of each match and the text caught by each group.
- To test a find and replace, type into Replace with. The changed text appears in Result, ready to copy.
Not sure where to start? Pick an entry from Common patterns. There are patterns for email addresses, web addresses, dates, IPv4 addresses, hex colours, phone numbers, numbers and double spaces.
The flags
| Flag | Name | What it changes |
|---|---|---|
| g | global | Finds every match, not just the first |
| i | ignore case | hello also matches Hello and HELLO |
| m | multiline | ^ and $ match at the start and end of each line |
| s | dot all | . also matches a new line |
| u | unicode | Reads emoji as one character and allows \p{...} classes |
| y | sticky | Each match must start exactly where the last one ended |
Examples
These results come from running the patterns in this tool.
| Pattern | Flags | Text | Matches |
|---|---|---|---|
\d+ |
none | a1 b22 c333 |
1 |
\d+ |
g | a1 b22 c333 |
1, 22, 333 |
hello |
gi | Hello hello HELLO |
Hello, hello, HELLO |
^\w+ |
gm | two lines: one two and three four |
one, three |
a.b |
g | a, new line, b |
no match |
a.b |
gs | a, new line, b |
one match |
The page loads with a date example. The pattern (?<year>\d{4})-(?<month>\d{2})-(?<day>\d{2}) finds three dates in the sample text: 2026-10-31, 2024-01-15 and 2026-11-02. The replacement $<day>/$<month>/$<year> turns the first one into 31/10/2026.
A replacement is also handy for cleanup. The pattern \s{2,} with a single space as the replacement turns too many spaces into too many spaces.
How it works
The tester builds a JavaScript RegExp from your pattern and flags, then runs it over the test text. With the g flag it keeps searching until the end. It also steps past empty matches, so a pattern like x* cannot loop forever.
The text is escaped before it is highlighted. Any HTML or script in your sample text is shown as plain characters and never runs.
Matching happens in a Web Worker, a background thread. If a pattern runs for more than 1 second, the worker is stopped and a fresh one is started. You see a message instead of a frozen tab.
If a pattern is invalid, you get the browser’s error message. For example, a lone ( gives “Unterminated group”.
Tips and limits
- Watch out for nested repeats. Patterns such as
(a+)+$or(\w+\s?)*$can take an enormous time on text that almost matches. This is called catastrophic backtracking. Make each part match something specific, and avoid a repeat inside a repeat. - Escape special characters. To match a real dot, write
\.. The same goes for? * + ( ) [ ] { } ^ $ |and the backslash itself. - Anchor your validation patterns. For a form field, wrap the pattern in
^and$so the whole value has to match, not just part of it. - Regex is not a full parser. It is fine for spotting emails or dates in text. It is not a reliable way to parse HTML or check that an email address really exists.
- Very large results are capped. The tool lists up to 5,000 matches and shows the first 300 rows in the details table.
Other ways to test a regex
On the command line, grep -oE prints each match on its own line:
echo 'Call 555-010-9999 on 2026-10-31' | grep -oE '[0-9]{4}-[0-9]{2}-[0-9]{2}'
That prints 2026-10-31. In Python, re.findall(r'\d{4}-\d{2}-\d{2}', 'from 2026-10-31 to 2024-01-15') returns ['2026-10-31', '2024-01-15']. In JavaScript, use text.match(/pattern/g) or text.matchAll() for groups.
Related tools
To clean up titles for web addresses, use the slug generator. To make text safe inside a link, use the URL encoder and decoder.