Regex Tester

Test a regular expression against your text and watch every match light up, with capture groups, a plain-English explainer and a find-and-replace preview. All local — your text never leaves your computer.

1 Pattern & test text — matches highlight as you type

Cheatsheet — click a token to insert it into the pattern
TokenMeaning
Any digit (0–9)
Any non-digit
Any word character (letter, digit, _)
Any whitespace (space, tab, newline)
Any character except a newline
0 or more of the previous token
1 or more of the previous token
0 or 1 of the previous token (optional)
Between 2 and 4 of the previous token
Start of string (or line, with m)
End of string (or line, with m)
Word boundary
Any one character in the range a–z
Any one character except a digit
Capture group
Non-capturing group
Named capture group
Or — this alternative or the next
Pattern explainer — what your pattern actually says

2 Matches — enter a pattern to begin

What is a regex tester?

A regular expression — regex for short — is a compact pattern that describes a set of strings: all email addresses, all dates in a certain format, every line that starts with a number. A regex tester is the place you try that pattern out before it goes into your code. You type the pattern, paste some sample text, and the tester shows you exactly what matches, where it matches, and what each captured group caught. Without one, debugging a regex means running your program, reading a wrong result, guessing which token is at fault, and starting over.

Regexes show up everywhere text needs to be searched, validated, or reshaped: form validation, log analysis, data cleaning, and search-and-replace in editors. The pattern itself is famously unreadable — a line of punctuation that does a lot of work — which is why seeing it run against real text matters more than reading it. This tester runs the JavaScript regex engine, the same one in every browser and in Node.js, so a pattern that works here works in your JavaScript code unchanged.

How to test a regular expression

  1. Enter a pattern in the top box. Type the pattern itself, without the surrounding slashes — \d+, not /\d+/. Or pick one from the Common patterns list: email, URL, IPv4, date, phone number, and more, each of which also loads matching sample text so you see a result immediately.
  2. Toggle the flags you need. g (global) is on by default so you see every match, not just the first. Add i for case-insensitive matching, m so ^ and $ work per line, s so . matches newlines, u for Unicode mode, or y for sticky matching.
  3. Paste test text into the test string box. Matches highlight instantly as you type — there is no button to press and no waiting. The match count sits above the preview.
  4. Read the match details. Every match is listed with its character position and each capture group, numbered and named. If a group is empty, it says so; if the pattern matched the wrong thing, the position tells you where.
  5. Try a replacement. Turn on find & replace, type a replacement using $1 for the first group or $<name> for a named group, and read the preview before the pattern goes anywhere near your code.
  6. Copy it out. Copy pattern copies the raw pattern; Copy as JS code copies the /pattern/flags literal ready to paste into JavaScript; Copy share link builds a URL that reopens the page with your pattern, flags, and test text filled in.

If the pattern is invalid, the tool says so in plain language and points at the approximate position of the problem instead of dumping the engine’s raw error at you. An unclosed group, a dangling backslash, or a bad quantifier all get a location you can look at.

Reading the results: matches, groups and flags

The highlighted preview is the fastest feedback loop: every match is painted in the test text itself, so you see at a glance whether the pattern caught too much, too little, or exactly the right span. A pattern like .+ that swallows a whole line is obvious the moment it lights up. The match list underneath is the precise version: “Match 2 — characters 34–52”, followed by each group. Numbered groups are the parentheses in order from left to right; named groups ((?<user>...)) show their names, which is what makes a long pattern readable six months later.

Flags change what the same pattern means, and the difference is worth seeing live. Without g, only the first match is found. Without i, [a-z]+ skips every capital letter. Without m, ^ matches only the very start of the whole text, so a pattern meant to catch “lines starting with a number” finds at most one line. The s flag matters whenever your text has line breaks and you used . — without it, a dot stops at the end of the line. The u flag turns on Unicode mode, which is required for Unicode property escapes like \p{L} and for correct handling of characters such as emoji. The y flag is the odd one out: it makes the pattern sticky, matching only at the exact position where the last match ended, which is useful when you are writing a small tokenizer and want the engine to fail loudly instead of skipping ahead.

The pattern explainer reads the pattern back token by token in plain English — what each character class, quantifier, group, and anchor does. It exists for the pattern you inherited from a colleague, or the one you wrote last month and can no longer read. A wall of punctuation becomes a short list of sentences, and the bug is usually the sentence that does not say what you meant.

Find and replace with capture groups

Matching is only half the job; the other half is reshaping. With replacement turned on, the tool applies your pattern to the whole test string and shows the result. The replacement text can refer back to what was captured: $1 is the first group, $2 the second, $& is the whole match, $<name> is a named group, and $$ is a literal dollar sign. A date pattern like (\d{2})/(\d{2})/(\d{4}) with the replacement $3-$2-$1 turns 15/08/2026 into 2026-08-15 — and you see it happen before committing. Groups that did not participate in a match are replaced with an empty string, exactly as JavaScript does it, so the preview is honest about what your code will produce. Test the replacement on the ugliest sample you have, not the cleanest: a pattern that reformats tidy dates perfectly can mangle a date with a single-digit day, and the preview is where that should surface — not in production data.

Ten patterns worth knowing

The library covers the patterns people reach for most. Email: [a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,} — a practical approximation, not a validator of every address the standard allows. URL: https?://[^\s/$.?#].[^\s]* for http and https links. IPv4: \b(?:\d{1,3}\.){3}\d{1,3}\b — it matches the shape, not the 0–255 range. Date: \b\d{4}-\d{2}-\d{2}\b for ISO dates. US phone: \+?1?[\s.-]?\(?\d{3}\)?[\s.-]?\d{3}[\s.-]?\d{4}. Hex color: #(?:[0-9a-fA-F]{3}){1,2}\b. Username: ^[a-zA-Z0-9_]{3,16}$. URL slug: ^[a-z0-9]+(?:-[a-z0-9]+)*$. HTML tag: <(\w+)[^>]*>.*?</\1> — the backreference \1 makes the closing tag match the opening one. Time: \b(?:[01]\d|2[0-3]):[0-5]\d\b for 24-hour times. Each one loads with sample text, and each is a starting point: tighten or loosen it against your own data, and watch the highlight change as you edit.

Common mistakes to avoid

  • Forgetting to escape the dot. . matches any character; a literal dot in an email or a filename needs \.. The pattern file.txt also matches fileXtxt.
  • Greedy quantifiers eating too much. <.*> on <b>hi</b> matches the whole string, not each tag. Use .*? (lazy) or a negated class like [^>]* when you want the shortest match.
  • Anchors without the m flag. ^\d+ matches a number at the start of the text only. Add m if you mean the start of every line.
  • Case sensitivity by default. Regexes are case-sensitive unless you add i. [a-z]+ will never match ABC.
  • Nested quantifiers that backtrack forever. Patterns like (a+)+$ on a long string of a’s can take an exponentially long time — the classic catastrophic backtracking. This tester stops runaway matches and warns you instead of freezing the tab; the fix is usually to simplify, for example a+$.
  • Validating with a pattern that is too strict. A “perfect” email regex rejects real addresses. Match the shape you actually need, and test against real examples, including the odd ones.

Frequently asked questions

Is this regex tester free?
Yes. No account, no limits, no upload. Your patterns and test text never leave your browser.
Which regex flavor does this tester use?
JavaScript (ECMAScript) — the same engine that runs in every web browser and in Node.js. Named capture groups, lookbehind and Unicode property escapes work when the u flag is on. Syntax from other flavors, such as PCRE-only (?P<name>) groups or possessive quantifiers, is not supported.
Why does my pattern match nothing?
The usual causes are an unescaped special character, a missing flag, or an anchor that cannot match where you expect. Check that . is not meant literally (use \.), that ^ and $ anchor to the whole string unless the m flag is on, and that the pattern is not accidentally case-sensitive — add the i flag.
What do the flags do?
g finds every match instead of just the first, i ignores case, m makes ^ and $ match the start and end of each line, s lets . match newlines, u turns on Unicode mode, and y makes the pattern sticky so it only matches at the current position.
How do I use capture groups in a replacement?
Turn on Replace and refer to groups in the replacement text: $1 is the first group, $2 the second, $& is the whole match, and $<name> is a named group. Use $$ for a literal dollar sign. The preview updates live, so you can see the result before copying the pattern into your code.
What does the pattern explainer do?
It reads your pattern back token by token in plain English — what each character class, quantifier, group and anchor does — so a pattern you inherited (or wrote last month) stops being a wall of punctuation.
Can a bad pattern freeze my browser?
Not here. Matching runs with a time budget and a match cap: a pattern that backtracks out of control is stopped and the tool tells you it was stopped, instead of hanging the tab. Simplifying nested quantifiers such as (a+)+ usually fixes the pattern.
Is my test text sent to a server?
No. Everything runs locally in your browser. That matters because people test regexes against real log lines, config files and data exports. You can verify it: load the page, disconnect from the internet, and the tool still works.

Privacy

Regex testers are where sensitive text goes: server logs, customer data, config files with credentials, email exports. Sending those to a server-side tester puts them in someone else’s log file. This tool compiles and runs the pattern locally, so the text stays on your machine. Close the tab and it is gone.

Worked example: pulling emails out of messy text

Suppose you have a support inbox export and need every email address in it. Start with the library’s email pattern — [a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,} — and paste in a chunk of the export. The highlights show two addresses at once, and the match list gives you their exact positions. Now suppose you also want the username part alone: wrap the front in a group, ([a-zA-Z0-9._%+-]+)@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,}, and the match details show group 1 holding just the username. Turn on replacement with $1 as the replacement text and the preview becomes a clean list of usernames — one per line, in place. If an address in the data uses a plus tag ([email protected]), it still matches, because + is in the character class. When the preview looks right on the messy sample, the pattern is ready for your code — copy it as a JavaScript literal and paste it in.

The habit that makes this reliable is testing against the worst sample, not the best. A pattern tuned on two clean addresses will happily miss the one with a subdomain or the one in all caps (add the i flag). Paste the ugly data first; the highlights will tell you the truth in seconds.

Share this tool

Copy the link below and paste it anywhere — a chat message, an email, a document. Whoever opens it gets the same free tool, with no account and nothing to install.

Related tools