Runs in your browser. Your files and text never leave your device - nothing is uploaded.
Test Regular Expressions Online
The Tools Kit’s free Regex Tester lets you write a regular expression, run it against your own sample text and see every match highlighted as you type. Each match is listed with the index where it starts and the values of its capture groups, and an optional replacement preview shows exactly what a find-and-replace would produce.
It uses your browser’s JavaScript regex engine, so a pattern that works here behaves the same way in front-end code and Node.js. Everything runs on your device: the pattern and test text are never uploaded, which makes it safe to debug against real log lines or customer data.
How to Use the Regex Tester
- 1
Enter the pattern
Type your regular expression into the Regular Expression field without the surrounding slashes, for example (\d{4})-(\d{2})-(\d{2}) rather than /(\d{4})-(\d{2})-(\d{2})/.
- 2
Set the flags
Type flags such as g, i, m or s into the Flags box. If the pattern or flags are invalid, the engine’s error message appears under the fields.
- 3
Paste your test string
Add the text you want to search in the Test String box. Matches are highlighted on the right as you type and a count shows how many were found.
- 4
Check the match details
Read the Match Details list for each match, the index where it starts and the values of its capture groups. Use Copy all matches to copy every match, one per line.
- 5
Preview a replacement
Tick Test replacement and enter a replacement string, using $1, $2 for capture groups, to see the rewritten text and copy it.
Matching and highlighting always search the whole text, even if you leave out the g flag. The replacement preview follows your flags exactly, so add g when you want every match replaced.
Regex Flags Explained
Flags change how the whole pattern is applied. Type them as letters in the Flags box in any order; the tester accepts every flag your browser supports and reports an error for unknown or repeated ones.
| Flag | Name | Effect |
|---|---|---|
| g | global | Find all matches rather than stopping after the first; matters for the replacement preview here |
| i | ignore case | cat also matches Cat and CAT |
| m | multiline | ^ and $ match at the start and end of each line, not only the whole text |
| s | dotAll | The dot (.) also matches newline characters |
| u / v | unicode / unicodeSets | Treat the pattern as Unicode code points and enable \p{...} property escapes |
| y | sticky | Each match must start exactly where the previous one ended |
The default example shows why the m flag matters. The pattern ^[a-zA-Z]+$ with only the g flag finds no matches in the three-line sample, because ^ and $ refer to the start and end of the entire text. Add m and it finds Bar at index 19: the only line made up entirely of letters, since Hello World contains a space and Foo123 contains digits.
Capture Groups and Find-and-Replace
Parentheses capture part of a match so you can reuse it. Test the pattern (\d{4})-(\d{2})-(\d{2}) with the g flag against 2026-10-02 and 2025-01-15 and Match Details shows two matches: 2026-10-02 at index 0 with groups 2026, 10, 02, and 2025-01-15 at index 15 with groups 2025, 01, 15.
Now tick Test replacement and enter $3/$2/$1. The preview reads 02/10/2026 and 15/01/2025. Remove the g flag and only the first date is rewritten, which is the most common surprise when a replace in code changes less than expected. Named groups work too: (?<first>\w+) (?<last>\w+) with $<last>, $<first> turns John Smith into Smith, John. Match Details lists named groups by position rather than by name.
Once a substitution looks right, paste the before and after text into the text compare tool to review every change line by line before you run it across a codebase.
Greedy vs Lazy Matching and Other Common Mistakes
Quantifiers are greedy by default and grab as much text as they can. Against <p>one</p><p>two</p>, the pattern <p>.*</p> returns a single match spanning both paragraphs, while the lazy version <p>.*?</p> returns two. For real HTML or XML, a parser is safer than a regex; the XML formatter is a better way to inspect markup structure.
Other frequent problems are an unescaped dot (. matches any character, so use \. for a literal period), forgetting the i flag for mixed-case input, and nested quantifiers such as (a+)+. The last one can cause catastrophic backtracking, and because this tester matches on every keystroke, such a pattern on a long string can make the tab stop responding.
Some jobs are easier without writing a pattern at all. To check whether an email address's domain can actually receive mail, not just whether it looks well-formed, use the email validator; to turn a title into a clean URL segment, the slug generator does it in one step; and to strip repeated lines from a list, try remove duplicate lines.
Common uses
- Writing validation patterns for form fields such as usernames, postcodes or phone numbers
- Extracting IDs, timestamps or IP addresses from log lines with capture groups
- Previewing a search-and-replace before running it in an editor or script
- Debugging a pattern copied from Stack Overflow or an old codebase
- Learning how anchors, flags and lazy quantifiers change what matches
Regex often sits next to other data work: pull values out of a response, then tidy it in the JSON formatter, or decode percent-encoded query strings with the URL decoder before matching against them. Browse all developer tools for more utilities.
Regex terms explained
| Term | What it means |
|---|---|
| Pattern | The regular expression itself, typed here without the / delimiters used in JavaScript source code |
| Flag | A single letter that changes how the whole pattern behaves, such as g (global) or i (ignore case) |
| Character class | A set of allowed characters in square brackets, such as [a-z], or a shorthand such as \d (digit) or \w (word character) |
| Quantifier | How many times the previous item may repeat: *, +, ?, {3} or {2,5}; add ? to make it lazy |
| Anchor | A position rather than a character: ^ start, $ end, \b word boundary |
| Capture group | Part of a pattern in parentheses whose matched text is saved and can be reused as $1, $2 in a replacement |
| Lookahead / lookbehind | A zero-width check that text does, or does not, follow (?=...) or precede (?<=...) the current position |
Frequently Asked Questions
A regex tester is a tool for trying a regular expression against sample text before you use it in code. You type a pattern and some text, and it shows what matches, where each match starts and what each capture group captured, so you can fix mistakes before they reach production.
It uses the JavaScript (ECMAScript) engine built into your browser, so results are the same as RegExp in front-end code and Node.js. Python, PCRE, Java and Go are close but not identical; features such as possessive quantifiers, atomic groups and inline modifiers differ, so recheck advanced patterns in your target language.
No. Type only the pattern, such as \d+, in the Regular Expression field and put flags such as gi in the separate Flags box. Typing /\d+/ would make the slashes part of the pattern and search for literal slashes.
g (global) finds every match instead of only the first, i ignores letter case, m (multiline) makes ^ and $ match at the start and end of every line, and s (dotAll) lets the dot match newline characters. Your browser also accepts u and v for Unicode mode, y for sticky matching and d for match indices.
Common causes are anchors without the m flag, case differences without the i flag, and special characters that need escaping. The default example shows the first one: ^[a-zA-Z]+$ with only g finds nothing in the three-line sample, because ^ and $ refer to the whole text; adding m finds Bar at index 19.
Yes for highlighting and the Match Details list, which always search the whole text. The replacement preview, however, uses your flags exactly as typed, so without g only the first match is replaced, just as String.replace behaves in JavaScript.
Wrap parts of the pattern in parentheses and refer to them as $1, $2 and so on in the replacement field. For example, (\d{4})-(\d{2})-(\d{2}) with replacement $3/$2/$1 and the g flag turns 2026-10-02 into 02/10/2026. Named groups can be used with $<name>, and $& inserts the whole match.
A greedy quantifier such as .* takes as much text as it can, while a lazy one such as .*? takes as little as possible. On <p>one</p><p>two</p>, the pattern <p>.*</p> returns one match covering both paragraphs, while <p>.*?</p> returns two separate matches.
The pattern or flags are not valid JavaScript regex syntax, and the engine’s own message is shown under the fields. Typical errors are an unclosed parenthesis or bracket, a quantifier with nothing before it, and an unknown or repeated flag such as gg.
Yes. Matching runs on every keystroke with no time limit, so a pattern with nested quantifiers such as (a+)+$ tested against a long non-matching string can trigger catastrophic backtracking and make the tab unresponsive. Rewrite such patterns to avoid nested repetition.
No. The Regex Tester runs entirely in your browser using its built-in regex engine. Your pattern, test text and replacement are not uploaded or saved, and they are cleared when you reload the page.
Reviewed by Raja Jahangir · Last reviewed: October 7, 2026
How do you test a regular expression?
To test a regex, enter the pattern and some sample text, and every match is highlighted as you type, with capture groups listed separately. Testing against real sample data catches the common failures - greedy quantifiers, unescaped dots, and anchors - before the pattern reaches production.
