Regex tester

Test and debug regular expressions with live match highlighting, capture groups and flags. Runs entirely in your browser.

/ / g
Test string
0 matches
Regex quick reference
Send matches to:

Ctrl + L clear test string

About regular expressions

A regular expression, or regex, is a compact pattern that describes a set of strings. Instead of searching for one fixed word, a regex lets you search for a shape — an email address, a phone number, a date, an HTML tag — and find every piece of text that fits it. That power is why regex appears in almost every programming language, in text editors and command-line tools like grep and sed, and in the search-and-replace boxes of professional software. The trade-off is that regex syntax is famously terse, so an interactive tester that highlights matches as you type is the fastest way to build a pattern correctly and understand why it does or does not match.

History of regular expressions

The idea began in 1951 with mathematician Stephen Cole Kleene, who formalised "regular sets" to describe patterns in the theory of computation — the asterisk quantifier is still called the Kleene star in his honour. Regular expressions moved from theory to practice in the late 1960s when Ken Thompson built them into the QED and ed editors and, soon after, the Unix grep command. The syntax most developers know today was shaped by Perl in the late 1980s, whose powerful extensions became the de facto standard and were later codified as PCRE (Perl Compatible Regular Expressions). JavaScript's regex engine, which powers this tester, follows the ECMAScript specification and is closely related to that Perl-derived tradition.

How regex flags work

Flags are single letters appended after the closing delimiter that change how the entire pattern is applied. The global flag (g) tells the engine to find every match rather than stopping at the first, which is what turns a search into a find-all. The ignore-case flag (i) makes letters match regardless of case. The multiline flag (m) changes the anchors ^ and $ so they match at the start and end of each line instead of the whole string, and the dotall flag (s) lets the dot match newline characters. The unicode flag (u) unlocks full Unicode handling and property escapes, and the sticky flag (y) forces each match to begin exactly where the last one ended. Toggling these on this page updates the highlighted results instantly, which makes flags much easier to learn by experiment than by reading.

Common regex use cases

Regular expressions are the standard tool for validating and extracting structured text: checking that an email address or postal code is well formed, pulling all the dates or dollar amounts out of a document, or stripping HTML tags from a block of content. Developers use them to search codebases, rewrite URLs on web servers, and parse log files, while writers and data-cleaners use them inside editors to reformat lists and fix inconsistent punctuation across thousands of lines at once. Because the same pattern can transform a whole file in one pass, getting the regex exactly right matters — and testing it against real, messy sample text before you run it is what prevents a pattern from quietly matching too much or too little.

Frequently asked questions

Which regex flavor does this tester use?

It uses the JavaScript (ECMAScript) regular expression engine built into your browser, the same one that runs inside every website and Node.js application. That means the syntax here matches what you would write in JavaScript exactly — lookaheads, named groups with (?<name>...), and Unicode property escapes with the u flag all work. It differs in small ways from PCRE, Python's re module or .NET regex, so a pattern copied from another language may need minor adjustments, most commonly around lookbehind support and possessive quantifiers, which JavaScript handles differently.

What do the g, i, m, s, u and y flags do?

Flags change how the whole pattern behaves. g (global) finds every match instead of stopping at the first. i (ignore case) makes letters case-insensitive. m (multiline) makes ^ and $ match at the start and end of each line rather than the whole string. s (dotall) lets the dot match newline characters too. u (unicode) enables full Unicode and property escapes. y (sticky) anchors each match to the exact position where the previous one ended. Toggle them on and off here to watch the highlighted matches update instantly.

How do capture groups work?

Parentheses in a pattern create a capture group that remembers the part of the text it matched, so a pattern like (\d{4})-(\d{2})-(\d{2}) pulls the year, month and day out of a date as groups 1, 2 and 3. This tester lists every group under each match so you can see exactly what was captured. Use (?<year>\d{4}) to give a group a name, or (?:...) for a non-capturing group when you need to group part of a pattern without saving it.

Why does my regex match too much or too little?

The usual culprit is greedy quantifiers. By default * and + match as much as possible, so .* in a tag-stripping pattern will swallow everything up to the last closing bracket on the line. Add a question mark to make them lazy — .*? matches as little as possible — or replace the dot with a more specific character class like [^>]* that cannot cross the boundary you care about. Testing against realistic sample text here, with several edge cases pasted in, is the fastest way to see greedy behaviour and fix it.

Why am I getting an "Invalid regular expression" error?

The pattern is not valid JavaScript regex syntax, usually because a special character is unbalanced or unescaped. Unmatched parentheses or square brackets are the most common cause, followed by a trailing backslash or a quantifier with nothing before it. Characters with special meaning — . * + ? ( ) [ ] { } ^ $ | \ / — must be escaped with a backslash when you want to match them literally, so to match a real dot you write \. and to match a slash you write \/. The exact error message from the browser appears below the pattern to help you locate the problem.

Is my test data kept private?

Yes. The pattern and the text you test against are processed entirely in your browser using the native RegExp engine, and nothing is ever sent to a server, logged or stored. That makes it safe to test regexes against real log files, production data or anything sensitive. You can confirm this by loading the page, disconnecting from the internet, and watching the tool keep working offline.