Black Friday: 50% off every paid plan with code BF50. Ends 5 December.

See prices

Free tool

Regex tester, matches as you type.

Type a regular expression and some test text, and every match is highlighted as you type, with its position and each capture group, named groups included. Read the pattern explained in plain English, switch flags on and off, preview a replace with $1 and $<name>, and export the matches. It runs your browser's JavaScript regex engine in the background with a time limit, so a runaway pattern never freezes the page.

Need a custom tool, app or website? Contact us 

JavaScript (ECMAScript) flavour, run by this browser's engine.

Test text

Matches

    Replace

    
            

    What the pattern says

      Cheat sheet

      Click to put it into the pattern at the cursor.

      Start from

      Use it in code

      Keys

      • / Edit the pattern
      • Enter Next match
      • Shift Enter Previous match
      • Cmd S Download matches

      Tested in your browser. Nothing is sent anywhere. Your pattern, flags and replacement are remembered on this device; the test text is not.

      See what matches

      Every match, every group.

      01 / Live

      Highlights as you type

      Matches are marked in the text in alternating colours. Press Enter in the pattern to step through them.

      02 / Explained

      The pattern in plain English

      Each piece of the pattern is spelled out, groups are numbered, and risky nested repeats are flagged.

      03 / Safe

      Never freezes

      Matching runs in the background with a 2 second limit, so a runaway pattern is stopped, not your tab.

      Guide

      How to test a regex, one piece at a time.

      A regex tester lets you write a regular expression, paste some sample text, and see straight away what the pattern matches. This one highlights every match, lists each one with its position and capture groups, explains the pattern in plain English, and shows what a replace would produce. It uses the JavaScript regex engine built into your browser, the same one your code uses in a web page or in Node.

      How to use the regex tester

      1. Type your pattern between the two slashes at the top. Leave out the slashes themselves.
      2. Turn flags on or off with the g, i, m, s, u, v and y buttons. The line under the pattern says in words what the flags you picked do.
      3. Paste your text into Test text, press Open file, or drop a text file on the box. Matches are highlighted as you type.
      4. Read the Matches list: each match shows its number, the text, where it starts and ends, and every group it captured, by number and by name. Click a match to select it in the text, or press Enter in the pattern to step through them.
      5. Check What the pattern says to read your pattern piece by piece.
      6. Type into Replace with to preview a find and replace, then copy or download the result.
      7. Press Download CSV or JSON to save the matches, or Copy link to share the pattern, flags, replacement and text.

      Regex cheat sheet

      WriteMatches
      .Any one character except a line break (add the s flag to include line breaks)
      \d \w \sA digit, a word character (letter, digit or underscore), a space or other whitespace
      \D \W \SThe opposite of each of the above
      [abc] [^abc]One of a, b or c; any one character that is not a, b or c
      [a-z]One character in the range a to z
      * + ?Zero or more, one or more, zero or one of the thing before
      {3} {2,5} {2,}Exactly 3, between 2 and 5, or 2 or more of the thing before
      *? +?The same repeats, but taking as little as possible (lazy)
      ^ $Start and end of the text (or of each line, with the m flag)
      \bA word boundary, the edge between a word character and anything else
      (abc)A capture group, listed as group 1, group 2 and so on
      (?<year>\d{4})A named group, listed by its name
      (?:abc)A group that is not captured, for applying a repeat or a choice
      a|ba or b
      (?=x) (?!x)Only if followed by x; only if not followed by x
      (?<=x) (?<!x)Only if after x; only if not after x
      \1 \k<name>The same text that group 1, or the named group, matched
      \p{L}Any letter in any language (needs the u or v flag)
      \. \( \\A literal dot, bracket or backslash

      The flags

      • g (global) finds every match. Without it only the first match is listed and replaced.
      • i (ignore case) lets a match A.
      • m (multiline) makes ^ and $ match at each line, not only at the start and end of the text.
      • s (dot all) lets . match line breaks too.
      • u (unicode) reads the pattern as full Unicode: \p{...} classes work, an emoji counts as one character, and unknown escapes are errors.
      • v (unicode sets) does all that u does and adds set operations inside square brackets, like [\p{L}--[a-z]]. You can turn on u or v, not both. The button only shows if your browser supports v.
      • y (sticky) makes each match start exactly where the last one ended.

      Build a pattern step by step: a worked example

      Say you want UK style dates like 17/10/2026 out of a block of text. Start small and watch the highlights after each step.

      1. Type \d+. Every run of digits lights up, including 17, 10 and 2026 separately.
      2. Make it \d{2}/\d{2}/\d{4}. Now only the full date matches.
      3. Add named groups: (?<d>\d{2})/(?<m>\d{2})/(?<y>\d{4}). The list shows d as 17, m as 10 and y as 2026.
      4. Type $<y>-$<m>-$<d> into Replace with. The preview turns 17/10/2026 into 2026-10-17.
      5. Add \b at both ends so it does not match inside a longer number like 123/45/67890.

      Replace patterns

      • $1, $2: the text of that numbered group.
      • $<name>: the text of a named group.
      • $&: the whole match. [$&] wraps every match in square brackets.
      • $` and $': the text before and after the match.
      • $$: a literal dollar sign.

      With the g flag on, every match is replaced. With it off, only the first one is.

      Why a pattern does not match

      • A special character is not escaped. example.com also matches exampleXcom, because the dot means any character. Write example\.com.
      • Too many backslashes. In code you often write "\\d" inside a string. In the pattern box, write just \d. The Use it in code box writes the string form for you.
      • The match is too greedy. ".*" on a line with two quoted words grabs everything from the first quote to the last. Add a question mark, ".*?", to stop at the nearest quote.
      • ^ and $ only match once. Without the m flag they mean the start and end of the whole text. Turn on m to match each line.
      • Case. Patterns are case sensitive. Turn on the i flag to ignore case.

      Slow patterns and catastrophic backtracking

      Nested repeats such as (a+)+$ or (\w+\s?)*$ can make the engine try a huge number of ways to split the text when it almost matches. The time grows very fast with each extra character, and in your own code that can hang a page or a server. Here the matching runs in a background worker. If it takes more than 2 seconds, the tester stops it, says so, and the page stays usable. The explanation panel also marks nested repeats. To fix one, use a single repeat where you can, make the parts inside unable to match the same text, or anchor the pattern.

      JavaScript regex compared with other languages

      Most everyday syntax, like classes, groups, repeats and anchors, works the same in JavaScript, Python, PHP, Java and .NET. The differences are in the edges. JavaScript has no possessive quantifiers or atomic groups, Python writes named groups as (?P<name>...), and flags go after the closing slash rather than inside the pattern. If your pattern is for another language, test the final version there too.

      Cleaning up text before you search it? The remove line breaks tool joins wrapped lines, and the case converter changes text to upper, lower or title case.

      Questions

      Good to know.

      Which regex flavour does it use?

      JavaScript's (ECMAScript), built into your browser. PCRE, Python and others are close but differ in places like named group syntax, possessive repeats and atomic groups.

      What do the flags do?

      g finds every match, i ignores case, m makes ^ and $ work per line, s lets . match new lines, u turns on full Unicode, v adds set operations on top of u, and y matches only where the last match ended.

      Why does my pattern match nothing?

      Check escaping first: a backslash in the pattern box is just one backslash, unlike in many code strings. Then read What the pattern says, which spells out each piece.

      Can I use named groups?

      Yes: (?<year>\d{4}). They are listed by name, and you can use $<year> in the replacement.

      Is my text sent anywhere?

      No. Everything runs in your browser. The test text is not even saved, unless you copy a link, which puts it in the link itself.

      Why did it stop and say the pattern took too long?

      The pattern needed more than 2 seconds on this text, which almost always means nested repeats that backtrack. The tester stops the search so the page does not freeze. See the section on catastrophic backtracking above for how to fix it.

      How do I match a whole word only?

      Put \b on both sides, like \bcat\b. It matches cat on its own but not inside catalog or concat.

      What is the difference between greedy and lazy matching?

      A greedy repeat like .* takes as much text as it can, then gives some back if it has to. A lazy repeat like .*? takes as little as it can. Use lazy when you want to stop at the first closing quote or tag.

      How do I match a line break in regex?

      Use \n for a line break, or \r?\n to also cover Windows line endings. To let a dot match line breaks too, turn on the s flag.

      Does the regex tester save my pattern?

      Yes, in this browser only. Your pattern, flags and replacement come back when you reopen the page. The test text does not, so private text is not left behind.

      Listed on

      Listed on JustMacAppsMotionShine on Mac App IndexMotionShine on ScrollLaunchMotionShine featured on StartupBaseFeatured on FazierFeatured on Twelve ToolsMotionShine - Featured on Smol Launch