How to use the Regex Tester
- Type your pattern between the slashes, or choose one from Common patterns. You can also paste a full literal like
/\d+/g. - Toggle flags such as
g(all matches),i(ignore case) orm(multiline). - Paste your text into Test string — every match is highlighted as you type.
- Check the Matches tab for positions and capture groups, or open Replace to preview a substitution.
- Click Copy to grab the regex as
/pattern/flags; the pattern and flags are also kept in the page URL for sharing.
What is a regex tester?
A regular expression (regex) is a compact pattern language for finding and transforming text — validating an email field, extracting IDs from logs, renaming files or cleaning data. Because a single character can change what a pattern matches, writing regex by trial and error inside your code is slow. A regex tester shows you instantly what a pattern matches, which capture groups it fills and what a replacement would produce.
This tester uses your browser’s own JavaScript (ECMAScript) regex engine, so results are exactly what String.prototype.match, matchAll, replace and RegExp.test give you in Chrome, Firefox, Safari, Node.js and Deno. Patterns run in a background worker with a time limit, so a runaway pattern can’t freeze the page.
JavaScript regex flags
| Flag | Name | Effect |
|---|---|---|
g | global | Find every match instead of stopping at the first. |
i | ignoreCase | /abc/i matches “ABC”. |
m | multiline | ^ and $ match at the start and end of every line. |
s | dotAll | . also matches line breaks. |
u | unicode | Treats surrogate pairs (emoji) as one character and enables \p{…} property escapes. |
y | sticky | Matches only at lastIndex — useful when writing tokenizers. |
Capture groups, named groups and replacements
Parentheses capture the text they match. In (\d{4})-(\d{2}) group 1 is the year and group 2 the month. Named groups make patterns self-documenting: (?<year>\d{4}) is available as match.groups.year in code and as $<year> in a replacement string. For example, replacing (?<y>\d{4})-(?<m>\d{2})-(?<d>\d{2}) with $<d>/$<m>/$<y> turns 2026-10-25 into 25/10/2026. Use (?:…) when you need grouping without capturing.
Catastrophic backtracking
Patterns with nested quantifiers such as (a+)+$ or (\w+\s?)*$ can take exponential time on input that almost matches — a classic cause of frozen browsers and ReDoS vulnerabilities on servers. If a pattern runs longer than 1.5 seconds here, it is stopped and flagged. Fix it by making alternatives mutually exclusive, replacing .* with a negated class like [^"]*, or anchoring the pattern.
Tips for reliable patterns
- Anchor validation patterns with
^…$, otherwise\d{5}also “validates”abc123456. - Escape literal metacharacters:
\.\?\(\[\$. - Prefer specific classes over
.*; they are faster and match what you mean. - Regex is a poor fit for nested formats like HTML or JSON — use a parser (or our JSON Formatter).
- Comparing the text before and after a replace-all? Paste both into the Diff Checker.
Tools that pair well with the Regex Tester
- JavaScript Formatter — Unminify and pretty-print JavaScript, JSON or JSX with your preferred indentation and brace style — or strip whitespace and comments with a verified minifier.
- URL Encode / Decode — Percent-encode text for safe use in URLs, decode encoded strings back to readable text, and break any URL down into its parts and query parameters.
- Slug Generator — Convert any title into a clean, lowercase URL slug — with proper transliteration of accents, umlauts and Cyrillic, optional stop-word removal and a bulk mode for whole lists.
- Remove Duplicate Lines — Paste a list to remove duplicate lines instantly.
Frequently asked questions
Which regex flavour does this tester use?
\A/\Z anchors or inline modifiers like (?i).Why does my pattern only find one match?
g (global) flag, JavaScript stops at the first match. Turn on g to find them all — the tester also reminds you when it is off.How do I match across multiple lines?
m flag so ^ and $ work per line, and the s flag (or [\s\S]) if . should also match newline characters.Is my test text stored or uploaded?
What is a good regex for validating email addresses?
^[^\s@]+@[^\s@]+\.[^\s@]+$ (or the “Email address” preset). Fully RFC 5322-compliant patterns are enormous and still can’t tell you whether the mailbox exists — send a confirmation email for that.