Skip to content
Browser tool Runs locally

Regex Tools

Test regular expressions against text in your browser.

Tools

What regex is for

A regular expression describes a pattern of text rather than a fixed string, which is what makes it useful for validating input formats (an email address, a phone number), pulling specific pieces out of a larger block of text, and search-and-replace that needs to match a shape rather than exact characters. Regex Tester lets you check a pattern against real sample text before it goes anywhere near production code.

JavaScript's flavor vs. PCRE and Python

This tool runs the native JavaScript RegExp engine, the same one your browser uses everywhere else, which follows the ECMAScript regex spec. It's close to PCRE (used by many other languages) and Python's re module for everyday patterns, but a few differences catch people out: JavaScript has no inline flags like (?i), named groups are written (?<name>...) rather than (?P<name>...), and some POSIX classes like [:alpha:] don't exist here at all. A pattern tested here should transfer cleanly to most JavaScript code, but verify it separately before reusing it in Python, PHP, or another PCRE-based environment.

Greedy quantifiers and anchors

Two habits catch most people early on. Quantifiers (*, +, {n,m}) are greedy by default, they match as much as possible, so a pattern like <.*> against text with several tags spans from the first < all the way to the last > instead of matching one tag at a time; add a ? (*?, +?) to make it lazy instead. And without anchors, a pattern matches anywhere it finds a hit inside the string, not the whole thing, use ^ and $ to require a full match rather than a partial one buried in the middle.

Test before you ship

A pattern that works on the one example you wrote it against can still fail on real input with edge cases you didn't think of, extra whitespace, unexpected casing, or a character you forgot to escape. Run a pattern against a handful of both valid and deliberately invalid sample inputs here before dropping it into validation or parsing code, catching a bad pattern in a text box is a lot cheaper than catching it in production.

Frequently asked questions

What regex flavor does this tool use?
The native JavaScript RegExp engine built into your browser (the ECMAScript regex specification). It's close to PCRE and Python's re module for common patterns, but not identical, so double-check anything you plan to reuse in a different language.
Why did a pattern that works in Python fail here?
A few syntax differences trip people up most: inline flags like (?i) aren't supported in JavaScript, named groups use (?<name>...) rather than (?P<name>...), and some POSIX character classes like [:alpha:] don't exist at all. If a pattern parses elsewhere but not here, one of these is the usual cause.
Why did my quantifier match way more than I expected?
Quantifiers like * and + are greedy by default, they grab as much as possible and only back off if the rest of the pattern can't match otherwise. On something like <.*> against multiple tags, greedy matching spans from the first < to the last >, not just one tag. Add ? after the quantifier (*?, +?) to make it lazy and match as little as possible instead.
Why does my pattern match in the middle of a string when I wanted the whole thing?
Without anchors, a regex matches anywhere it can find a match, not the full input. Add ^ at the start and $ at the end to require the pattern to match the entire string (or the full line, with the m flag), rather than matching a substring somewhere inside it.
Why doesn't my literal dot, parenthesis, or slash work as expected?
Characters like . () [] {} + * ? ^ $ | \ and / all have special meaning in a regex. To match one of them literally, escape it with a backslash, such as \. for a literal period. Forgetting to escape a period is one of the most common reasons a pattern matches more than intended.