Regex Tester
A free tool by DeepRit, a Google Ads agency that does PPC and nothing else. We build and run Google Ads accounts so every click is accounted for. Book a free audit call
Free regex tester. Write a regular expression, see every match highlighted, check capture groups and preview replacements, all as you type.
- Matches
- 0
- Groups
- 0
- Time
- 0
Free, no sign-up. Runs in your browser: nothing you type is uploaded or saved.
How to use the regex tester
Type a regular expression and its flags, then paste the text you want to test. As you type, the regex tester:
- Highlights every match in your text, alternating colours so neighbouring matches are easy to tell apart.
- Counts the matches and capture groups, and shows how long the search took.
- Lists each match with its position and every capture group in a table.
- Previews a replacement: type a replacement such as
$1 at $2to see the text after replacing.
Errors in your pattern are explained as you type. Patterns run in a separate background thread, so a pattern that would run forever is stopped after two seconds instead of freezing the page.
The regex tester uses your browser's JavaScript regular expression engine, and nothing you type is uploaded.
Regular expression basics
A regular expression (regex) is a pattern that describes text. Most characters match themselves; special characters have special meanings.
Characters
| Pattern | Matches |
|---|---|
. |
Any character except a line break |
\d |
A digit, 0 to 9 |
\w |
A letter, digit or underscore |
\s |
A space, tab or line break |
\D, \W, \S |
The opposite of the above |
[abc] |
One of a, b or c |
[^abc] |
Any character except a, b or c |
[a-z] |
Any lower-case letter from a to z |
\. |
A literal dot (the backslash "escapes" it) |
Quantifiers
| Pattern | Meaning |
|---|---|
* |
Zero or more |
+ |
One or more |
? |
Zero or one (optional) |
{3} |
Exactly 3 |
{2,5} |
Between 2 and 5 |
*?, +? |
As few as possible ("lazy") |
Anchors and boundaries
| Pattern | Meaning |
|---|---|
^ |
Start of the text (or of a line, with the m flag) |
$ |
End of the text (or of a line, with the m flag) |
\b |
A word boundary |
Groups
| Pattern | Meaning |
|---|---|
(abc) |
A capture group, available as $1, $2… in replacements |
(?<name>abc) |
A named capture group, available as $<name> |
(?:abc) |
A group that doesn't capture |
a|b |
a or b |
(?=abc), (?!abc) |
Followed by, or not followed by, abc (lookahead) |
(?<=abc), (?<!abc) |
Preceded by, or not preceded by, abc (lookbehind) |
Flags
| Flag | Name | Effect |
|---|---|---|
| g | global | Find every match, not just the first |
| i | ignore case | Treat upper and lower case the same |
| m | multiline | ^ and $ match at the start and end of each line |
| s | dotAll | . also matches line breaks |
| u | unicode | Full Unicode support, including \p{L} for any letter |
| v | unicodeSets | An upgraded unicode mode with set operations |
| y | sticky | Match only at the current position |
| d | indices | Record the start and end of each group |
Without the g flag, the regex tester shows only the first match, exactly as JavaScript would.
Useful patterns
| Task | Pattern |
|---|---|
| Email address (simple) | [\w.+-]+@[\w-]+\.[\w.-]+ |
| Web address | https?:\/\/[^\s]+ |
| US ZIP code | \b\d{5}(?:-\d{4})?\b |
| Date like 2026-11-13 | \b\d{4}-\d{2}-\d{2}\b |
| Time like 14:30 | \b([01]\d|2[0-3]):[0-5]\d\b |
| Hex colour | #(?:[0-9a-fA-F]{3}){1,2}\b |
| Repeated word | \b(\w+)\s+\1\b |
| Leading or trailing spaces | ^\s+|\s+$ |
| Hashtags | #[\p{L}\p{N}_]+ (with the u flag) |
These are practical patterns, not complete validators: a regex that matches every valid email address is famously long. For pulling emails and links out of text, the email extractor and URL extractor are ready-made.
Replacements
In the replacement box:
$1,$2… insert capture groups.$<name>inserts a named group.$&inserts the whole match.$`and$'insert the text before and after the match.$$inserts a literal dollar sign.
Example: pattern (\w+)@(\w+)\.com, replacement $1 at $2 turns "[email protected]" into "ana at crumbco".
For simple find-and-replace jobs without patterns, the find and replace tool is easier, and also supports regex.
Catastrophic backtracking
Some patterns take exponentially longer as the text grows, typically nested quantifiers like (a+)+ or (\w*)* followed by something that fails to match. On a long string, they can effectively run forever, freezing a page or even a server. This is called catastrophic backtracking, and it's behind real outages and security issues (ReDoS).
The regex tester runs your pattern in a background worker and stops it after two seconds, so you see a warning instead of a frozen tab. To fix such a pattern:
- Avoid nested quantifiers on overlapping patterns.
- Be specific:
[^"]*instead of.*inside quotes. - Anchor patterns with
^and$where possible.
JavaScript regex vs other flavours
The regex tester uses JavaScript's engine, the same one your browser, Node.js and most front-end code use. Most syntax is shared with Python, PHP (PCRE), Java and .NET, but there are differences: possessive quantifiers and atomic groups, for example, aren't available in JavaScript, and named groups use slightly different syntax in some languages. Test with the flavour your code uses.
Regex for data cleaning
Regular expressions are powerful for cleaning data before you use it:
- Remove extra spaces: replace
\s{2,}with a single space, or use remove extra spaces. - Find duplicate lines in a list, then remove them with remove duplicate lines.
- Pull out order numbers, codes or prices from pasted text.
- Check JSON or CSV fields, then tidy the data with the JSON formatter.
To compare two versions of a text before and after a replacement, use text compare.
How to build a regular expression step by step
Writing a regex all at once rarely works. Build it up, testing each step in the regex tester:
- Start with a literal example. To match order numbers like ORD-2026-0042, type exactly that and check it matches.
- Replace parts with classes. Change the digits to \d: ORD-\d\d\d\d-\d\d\d\d.
- Add quantifiers. ORD-\d{4}-\d{4} is shorter and clearer.
- Add boundaries. \bORD-\d{4}-\d{4}\b stops matches inside longer strings.
- Add groups for the parts you need. \bORD-(\d{4})-(\d{4})\b captures the year and the number.
- Test against tricky text: near-misses, text at the start and end of lines, and lines with several matches.
Reading other people's regex
To understand an unfamiliar pattern, paste it into the regex tester with some sample text, then remove parts one at a time and watch how the matches change. Long patterns are easier to read when you split them mentally at each group and alternation (|).
Regex vs simple search
Regular expressions are powerful but easy to get wrong. If you're searching for a fixed word or phrase, a plain search is simpler and safer. Reach for a regex when the text varies in a predictable way: numbers, dates, codes, email addresses, repeated words, or "this word but not that one".
Testing for edge cases
Before you use a regex in real code, test it against:
- Empty text.
- Text with no match at all.
- Text with several matches on one line.
- Upper and lower case.
- Accented and non-English letters, if your users might type them. \w only matches English letters, digits and underscore; with the u flag, \p{L} matches any letter.
- Very long text, to make sure the pattern stays fast.
Regex in other tools
Many everyday tools accept regular expressions: find and replace in code editors like VS Code, Google Sheets' REGEXMATCH and REGEXREPLACE functions, Google Analytics filters and many automation tools. Test patterns in the regex tester first; most follow the same basic rules.
A worked example
A bakery's developer exports a year of online orders as text and needs every customer email address from Gmail and Outlook accounts. In the regex tester, the pattern [\w.+-]+@(gmail|outlook)\.com with the flags gi highlights 412 matches, and the table shows the domain in group 1 for each. Testing a replacement of [hidden]@$1.com previews an anonymised version of the file to share with a colleague, and nothing ever leaves the browser.
Need more customers from Google?
This tool is free and runs in your browser. If your business also needs more leads or sales, Google Ads is where people search with their wallet out. That is the whole job of DeepRit: a PPC-only agency that sets up and runs Google Ads accounts so every click is accounted for. You keep full ownership of your account, get a written report every week, and can stop at any time. See our pricing or ask for a free audit.
Frequently asked questions
How do I test a regular expression?
Type the pattern and flags into the regex tester and paste your text. Matches are highlighted and listed as you type.
Which regex flavour does this use?
JavaScript, the engine built into your browser, used by Node.js and front-end code.
Why does my regex only find one match?
Add the g (global) flag to find every match.
How do I use capture groups in a replacement?
Use $1, $2 and so on for numbered groups, or $
Why was my pattern stopped?
It ran for more than two seconds, which usually means catastrophic backtracking from nested repeats. Make the pattern more specific.
Is the regex tester free?
Yes. It's free with no sign-up, and your text never leaves your browser.
Free PPC audit
See where your ad budget leaks.
We look at your Google Ads account before the call, then walk you through what we'd fix first, in dollars. No obligation, no hard sell.