FIRST CH TOOLS / 31 Regex Tester

Regex Tester

Type a pattern and some text, and every match is highlighted where it sits. The contents of each capture group, the position of every match and the result of a replacement are all on the same screen, and the g, i, m, s, u and y flags are one click away. JavaScript (ECMAScript) flavour — this page calls your browser's own RegExp.

It matches as you type

Pattern
/ /g
Text to test against
Highlighted matches
0
Matches
Groups
First at
Time
Matches & groups
Replace

Replacing is a preview only — the text above is left alone. \n and \t are read as escapes.

What we noticed

    Neither the pattern nor the text ever leaves your browser (matching runs on this page's own RegExp). You can also call it straight from a URL: /en/regex/?pattern=%5Cd%2B&flags=g&text=a1b22c333 or /en/regex/?pattern=…&flags=gi&replace=%5B%241%5D

    How to Use

    1. Enter a patternWrite the expression between the slashes. If you pasted it from code as /…/gi, one button strips the slashes and picks up the flags. You can also start from a common pattern (email address, URL, date and so on).
    2. Paste your textMatches light up on the right, and the position and capture groups of each one are listed below. Flip a flag and everything updates on the spot.
    3. Check the replacementPut $1 or $<name> in the replacement field to preview the result, then copy it straight out.

    About This Tool

    This is for checking that a regular expression does what you think it does. Type a pattern and some text, and matches are highlighted in place. Adjacent matches alternate colour, so you can tell where one ends and the next begins. Zero-length matches (a lone \b or a bare lookahead) are drawn as a thin bar, which means you can see the "nothing is highlighted but the count keeps rising" case instead of guessing at it.

    Every capture group, one match at a time. Alongside the matched text you get the value of each (…) group and where in the text it came from. Named groups such as (?<year>…) are labelled with their name, and groups that did not participate are shown as "(no match)" rather than left blank — handy when you are working out which branch of an | alternation fired.

    Try a replacement without touching the original. The replacement field understands $&, $1 and $<name>. Since a single-line field cannot hold a line break, \n and \t are read as escapes. Result to input moves the replaced text back into the input box, so you can stack several passes and see where you end up.

    It points out the usual traps. When a missing g flag limits you to one hit, when line breaks in the text make . or ^ / $ behave differently from what you expect, or when a nested quantifier like (a+)+ (the classic cause of ReDoS) shows up, the reason is spelled out below the results. Collecting matches is abandoned after one second (backtracking within a single attempt cannot be interrupted, so an extreme pattern may still stall the page briefly).

    JavaScript (ECMAScript) flavour. Because this page hands your pattern to the browser's own RegExp, anything that works here can be pasted straight into JavaScript or Node.js. Conversely, syntax that only exists in PCRE (PHP) or Python — \A, atomic groups, possessive quantifiers, extended mode — will not work. Turn on the u flag and \p{sc=Han} and friends let you target scripts by name.

    Nothing you type leaves your device. To compare before and after, use the Text & Code Diff Checker; to pull a URL apart, the URL Parameter Editor; and to make strings worth testing against, the Test Data Generator.

    Other Tools