My Tool Studio
Developer

Regex Tester

This regex tester runs your pattern against a test string as you type and highlights every match. It uses your browser's JavaScript engine, so results match Node.js and front-end code. Set the g, i, m, s, u, v, y and d flags, then use the tabs below: a match table with every capture and named group, Replace with $1 and $<name>, List to build output from each match, Split, and Explain, which describes the pattern token by token. Tests checks lines that should or should not match, Code turns the pattern into JavaScript, Python, PHP, Java, C# and Go, and Patterns loads ready-made regexes for emails, URLs, dates and phone numbers. Matching runs in a background worker with a time limit, so a runaway pattern cannot freeze the page.

Always freeNo sign upRuns in your browser
gi
Flags
0 matches
Reach us at hello@mytoolstudio.com or support@example.org any time.

No matches yet.

How to use

01

Type your pattern and flags

Enter the regular expression without the surrounding slashes and tick the flags you need. Pick an entry on the Patterns tab to load a ready-made pattern with sample text.

02

Paste the test text

Put the text to search in Test string. Matches are highlighted in alternating colors, and a syntax error, or a pattern that runs too long, appears in red.

03

Use the result tabs

Read the Match table, try a substitution under Replace, build output with List, or read Explain. Copy code for your language from the Code tab, or download the matches as CSV.

Why Regex Tester

JavaScript regex tester cheat sheet

These are the building blocks you will use most often. They work the same in this tester, in browsers and in Node.js. Combine them with the flags above the test string: g finds all matches instead of the first, i ignores case, m makes ^ and $ work per line, s lets . match line breaks, u turns on full Unicode, y makes each match start where the last one ended, and d records group positions.

TokenMeaningExample
.Any character except a line break (unless the s flag is on)a.c matches abc
\d, \w, \sDigit, word character (A-Z, a-z, 0-9, _), whitespace\d{3} matches 123
[abc], [^abc]One character from the set, or not in the set[aeiou] matches a vowel
^ and $Start and end of the text (or of a line with m)^Hello
*, +, ?0 or more, 1 or more, 0 or 1; add ? to make them lazya+? matches one a
{n,m}Between n and m repetitions\d{2,4}
( ) and (?: )Capture group and non-capturing group(\d+)-(\d+)
(?<name> )Named capture group(?<year>\d{4})
a|bEither a or bcat|dog
\bWord boundary\bcat\b skips concat
(?= ), (?! )Lookahead and negative lookahead\d+(?=px)
(?<= ), (?<! )Lookbehind and negative lookbehind(?<=\$)\d+

Replace, List and Split, side by side

The three output tabs use the same pattern in different ways. With the sample pattern (?<user>[\w.+-]+)@(?<domain>[\w-]+(?:\.[\w-]+)+) on the text hello@mytoolstudio.com or support@example.org:

TabSettingResult
Replace$<user> at $<domain>hello at mytoolstudio.com or support at example.org
List$<domain>\nmytoolstudio.com, then example.org on the next line
Split(no setting)The text between matches, plus each capture group, as a list

Common questions

Which regex engine does this tester use?
Your browser's built-in JavaScript RegExp engine, the same one your front-end code and Node.js use. Patterns written for PCRE (PHP), Python or .NET usually work, but some syntax differs, so test in the engine your code will run in.
Why does my regex match more text than I expected?
Quantifiers such as * and + are greedy: they take as much text as they can. <.+> on <b>hi</b> matches the whole string, not just <b>. Add ? to make them lazy, as in <.+?>, or use a narrower class such as <[^>]+>.
How do I match across multiple lines in a regex?
Tick multiline (m) to make ^ and $ match at the start and end of every line, not just the whole text. Tick dotAll (s) to let . match line breaks too. Without s, use [\s\S] when you need to match any character including a newline.
What does the index next to each regex match mean?
It is the position of the match in the test string, counting from 0; the Match table shows where each match starts and ends, such as 12-29. The start is the same index property that exec and matchAll return in JavaScript, so you can use it with slice or substring.
Why do I need to escape characters like . or ? in a regex?
Some characters have special meaning: . matches any character, and ? + * set how many times something repeats. To match them literally, put a backslash in front, as in \. for a real dot. The special characters are . ^ $ * + ? ( ) [ ] { } | and the backslash itself.
Does the regex tester support replace or substitution?
Yes. Open the Replace tab and type a replacement. $1 inserts group 1, $<name> a named group, $& the whole match and $$ a dollar sign. With the g flag every match is replaced, otherwise only the first, just like String.replace in JavaScript.
Why does my pattern work here but not in Python or PHP?
Engines differ in the details. Python's re module writes named groups as (?P<name>...), while JavaScript uses (?<name>...). PHP's PCRE supports possessive quantifiers and recursion, which JavaScript does not, and anchors such as \A and \Z do not exist in JavaScript. The Code tab converts named groups for Python and warns when Go cannot run a pattern.
Is the text I test with this regex tester sent to a server?
No. Matching runs in your browser, so the pattern and the test string never leave your device. You can safely test against log lines or data that contains personal details.
Can a regular expression freeze the page?
Not here. A pattern with nested quantifiers, such as (a+)+$, can take exponential time on some inputs, a problem known as catastrophic backtracking or ReDoS. This tester runs matching in a background worker and stops it after two seconds with a message, so the page stays responsive. Rewrite such patterns to avoid repetition inside repetition.
How do I see what a complicated regex does?
Open the Explain tab. It breaks the pattern into tokens, such as a character class, a quantifier or a lookahead, and describes each one in plain English, indented to show which group it belongs to. It is a quick way to review a pattern you found online before trusting it.

More Developer tools

View all