Developer Tools

Regex Tester

This free Regex Tester runs your regular expression against sample text in your browser's JavaScript engine, highlighting every match as you type and listing each match's index and capture groups. Tick Test replacement to preview a find-and-replace with $1, $2 group references. Nothing is uploaded.

Runs in your browser. Your files and text never leave your device - nothing is uploaded.

Hello World Foo123 Bar

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. 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. 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. 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. 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. 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.

FlagNameEffect
gglobalFind all matches rather than stopping after the first; matters for the replacement preview here
iignore casecat also matches Cat and CAT
mmultiline^ and $ match at the start and end of each line, not only the whole text
sdotAllThe dot (.) also matches newline characters
u / vunicode / unicodeSetsTreat the pattern as Unicode code points and enable \p{...} property escapes
ystickyEach 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

TermWhat it means
PatternThe regular expression itself, typed here without the / delimiters used in JavaScript source code
FlagA single letter that changes how the whole pattern behaves, such as g (global) or i (ignore case)
Character classA set of allowed characters in square brackets, such as [a-z], or a shorthand such as \d (digit) or \w (word character)
QuantifierHow many times the previous item may repeat: *, +, ?, {3} or {2,5}; add ? to make it lazy
AnchorA position rather than a character: ^ start, $ end, \b word boundary
Capture groupPart of a pattern in parentheses whose matched text is saved and can be reused as $1, $2 in a replacement
Lookahead / lookbehindA zero-width check that text does, or does not, follow (?=...) or precede (?<=...) the current position

Frequently Asked Questions

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.

Sources and standards