Skip to content
FileKit
Developer ToolsRuns in your browser6 min read

Regex Tester

This regex tester matches a regular expression against your text as you type, showing every match, its position, its capture groups, and a live preview of what a replace would produce. Enter a pattern, choose the flags, and results update immediately without a page reload or a request to a server.

Loading the tool interface
Files never leave your deviceNo upload wait and no queueNo signup, watermark or file limit

A regular expression is a compact way to describe a text pattern, and that compactness is exactly what makes it easy to write and hard to verify by reading alone. A single misplaced quantifier or an unescaped special character can change what a pattern matches in a way that is not obvious from the pattern text itself. Testing against real examples, both ones that should match and ones that should not, is the only reliable way to know a regex actually does what you intended.

Matching runs locally using the JavaScript engine already built into your browser, the same engine that will run the regex in production if it ends up in your code. Nothing you type here is sent anywhere, which matters when the text you are testing against contains real user data or private log lines.

What a regex tester shows you beyond a plain match or no match answer

For every match, this regex tester reports the matched substring, its start and end index in the original text, and the value of every capture group, both numbered and named. That level of detail matters because a pattern with the global flag set can match multiple times in one string, and a pattern with regex capture groups is usually being written specifically to extract a piece of that match, not just to confirm the whole thing matched.

The replace preview applies your replacement string, including backreferences like $1 for the first capture group, and shows the resulting text immediately, so you can confirm a find and replace pattern does exactly what you expect before you run it against a real file or paste it into code. Building that preview directly into a regex tester saves the step of copying a pattern out into a script just to check what a replace would do.

  • Highlights every match directly inside your sample text.
  • Lists numbered and named capture groups for each match separately.
  • Reports the character index where each match starts and ends.
  • Shows a live preview of the result of a replace with backreferences.
  • Supports the g, i, m, s and u flags, matching JavaScript's own regex engine.

Reading and choosing regex flags

The g flag finds every match in the text rather than stopping at the first one, and it is required if you want to see more than one result or if you plan to use the pattern with String.replaceAll. The i flag makes matching case insensitive, so A and a are treated as equivalent. The m flag changes how ^ and $ behave, making them match the start and end of each line rather than only the start and end of the whole string, which matters for multi line input. The s flag lets the . character match a newline, which it does not do by default. The u flag enables full Unicode matching, which affects how character classes and code points above the basic multilingual plane are interpreted.

Most everyday patterns need only g and i. Reach for m when working line by line through multi line text, s when a pattern needs to span line breaks, and u when the text contains emoji or characters outside the common Unicode range.

Guarding against catastrophic backtracking

Certain regex patterns, typically ones with nested quantifiers like (a+)+ or overlapping alternation, can take exponentially longer to fail a match as the input grows, a problem known as catastrophic backtracking or ReDoS. A pattern that runs instantly against a ten character string can freeze a browser tab against a two hundred character one, because the regex engine tries an enormous number of ways to backtrack before concluding there is no match.

This tool protects against that in two ways. Input length is capped, since the risk grows sharply with string length and a bounded input keeps worst case execution time bounded too, and every match attempt runs with a timeout, so a pattern that is taking dangerously long is abandoned with a warning rather than freezing the page. Neither protection changes how a well behaved pattern matches. Both exist purely to stop a runaway pattern from making the tool itself unusable.

How this regex tester works under the hood

Matching uses JavaScript's native RegExp object, the identical engine that runs a regular expression inside a Node.js script or a browser based application, so a pattern that works here behaves the same way once it ships in real code. As a javascript regex tool it introduces no separate dialect or simulation layer that could create a discrepancy between what you test and what production actually runs.

Because everything executes locally, there is no upload, no per request limit and no delay waiting on a server. Typing a new character into the pattern or the sample text re-runs the match immediately, which is what makes a regex tester built this way faster to iterate with than switching between an editor and a separate script just to check one pattern.

How to test a regular expression

  1. 1

    Enter your pattern

    Type a regular expression, without the surrounding slashes, into the pattern field.

  2. 2

    Choose flags

    Toggle g, i, m, s and u depending on whether you need global matching, case insensitivity, multi line anchors, dot-all or Unicode mode.

  3. 3

    Paste sample text

    Paste text that should and should not match, to confirm the pattern behaves correctly on both.

  4. 4

    Review matches and try a replace

    Check the highlighted matches and capture groups, then enter a replacement string to preview the result.

Related tools worth bookmarking

Sources and further reading

Frequently asked questions

Common questions about the regex tester.

Yes. It uses the browser's native RegExp object directly, the identical engine that executes a regular expression inside a Node.js script or a client side application. A pattern that matches correctly here will behave the same way once you put it into production code.

It is a performance problem in certain regex patterns, usually ones with nested quantifiers, where the engine tries an exponentially growing number of ways to backtrack before failing to match. This can freeze a browser tab or a server process on specific input, which is why this tool bounds input length and wraps every match attempt with a timeout.

Every match in the results list shows its capture groups underneath the full matched text, numbered in the order they appear in the pattern, with named groups shown by their name as well. A pattern with no parentheses has no capture groups beyond the full match itself.

No. Matching happens entirely in your browser using JavaScript's built in regex engine. Neither your pattern nor your sample text is ever transmitted, stored or seen by anyone but you, which matters when testing against real log lines or user data.

Without the g flag, a regex stops after finding the first match in the string. With it, the engine continues scanning and finds every non overlapping match, which is required if you expect to see more than one result or intend to use the pattern for a global replace.

Yes. Paste any amount of multi line text into the sample field. Enable the m flag if you want ^ and $ to match the start and end of each individual line rather than only the very start and end of the whole string, and enable s if you need the dot character to match across line breaks.