Regex Tester
//
2 matches
Test StringType or paste text to test against
Capture Groups0 groups · 2 matches
No capture groups. Use (…) to capture.
Quick Reference
.Any char except newline
\dDigit [0-9]
\wWord char [a-zA-Z0-9_]
\sWhitespace
\bWord boundary
^Start of string/line
$End of string/line
*0 or more
+1 or more
?0 or 1 (optional)
{n,m}Between n and m times
(abc)Capture group
(?:abc)Non-capture group
(?<n>…)Named group
[abc]Character class
[^abc]Negated class
a|bAlternation (a or b)
(?=…)Lookahead
(?!…)Neg. lookahead
(?<=…)Lookbehind

Regex Tester Online — Test JavaScript Regular Expressions

Share

About this tool

What Is This Regex Tester and How Does It Work?

This is a free, browser-based JavaScript regex tester that lets you write, test, and debug regular expressions in real time without writing any code. Type a pattern into the pattern bar, toggle the flags you need, paste your test string, and the tool highlights every match inline — colored spans directly inside the text area show you exactly where each match starts and ends. No button click, no page reload, no delay. Every change to the pattern, flags, or test string instantly re-runs the regex and updates all highlights, the match count, and the capture groups table.

Regular expressions are one of the most powerful tools in a developer's toolkit — and one of the most difficult to get right. A single misplaced character changes the meaning completely: forgetting to escape a dot, using the wrong quantifier, or not understanding how the m (multiline) flag changes the meaning of ^ and $ can all produce incorrect or surprising matches. Testing a regex in a developer console means repeatedly copy-pasting between the editor and the browser, and inspecting capture groups requires console.log with destructured match results. This online regex tester eliminates all of that friction by combining the pattern, flags, test string, match highlights, capture group inspection, and replace mode in a single focused interface.

The capture group table is the most useful feature for developers who write complex patterns with named or numbered groups. Wrap any part of your pattern in parentheses to create a capture group — the table automatically shows every match as a row, with each group's captured value in a separate column. Named capture groups using the (?<name>…) syntax show the group name as the column header, making complex patterns with multiple groups significantly easier to read and debug. The replace mode uses these same group references — $1, $2, $<name> — in the replacement string, letting you preview exactly what a JavaScript String.replace() call will produce before putting it in your code.

The 10 built-in presets cover the most common real-world pattern use cases: Email validation, URL matching, IPv4 address, Hex Color (#fff or #ffffff), ISO 8601 Date, US Phone number, HTML Tag extraction, JWT token format, Markdown Bold syntax, and CSS class name. Each preset loads the pattern, the appropriate flags, and a sample test string that demonstrates the matches and shows which groups capture which values. The quick reference panel lists 20 essential regex tokens with examples — from basic anchors (^ $) and quantifiers (? + * {n,m}) to lookahead (?=…) and lookbehind (?<=…) assertions, character classes, and word/digit/whitespace shortcuts.

Features

  • Live inline match highlighting — every match shown as a colored span in the test string as you type
  • Capture group table — shows every match as a row with each numbered or named group value in its own column
  • Named capture groups — (?<name>…) syntax with group name shown as column headers in the capture table
  • Replace mode — enter a replacement string with $1, $2, $<name> group references and preview the result live
  • All 5 JS flags — g (global), i (case-insensitive), m (multiline), s (dot-all), u (unicode) as toggle buttons
  • 10 ready-to-use presets — Email, URL, IPv4, Hex Color, ISO Date, US Phone, HTML Tag, JWT, Markdown Bold, CSS Class
  • Inline error display — shows the exact browser error message for invalid patterns
  • Match count in header — total match count and capture group count shown at a glance
  • Quick reference panel — 20 essential regex tokens with syntax examples
  • Copy button — copies pattern in /pattern/flags format with one click
  • 100% client-side — uses the native browser RegExp engine, nothing uploaded

How to Use

Type your regular expression pattern into the pattern bar at the top of the page. The pattern bar accepts the same syntax as JavaScript's RegExp — you do not need to include the surrounding forward slashes. Toggle individual flags using the lettered buttons beside the pattern bar: g for global (find all matches, not just the first), i for case-insensitive, m for multiline (makes ^ and $ match at line boundaries), s for dot-all (makes . match newline characters), and u for unicode mode (enables full Unicode codepoint matching and p{} property escapes).

Paste your test string into the large text area below the pattern bar. Matches are highlighted inline in real time as you type — each match appears as a colored background span directly inside the text. The match count above the test area shows how many matches were found. If your pattern contains an error (unclosed group, invalid escape sequence, etc.), a red error bar below the pattern input shows the exact browser error message rather than silently failing.

To inspect capture groups, wrap parts of your pattern in parentheses. The Capture Groups panel on the right lists every match with each group's captured value in a column. For numbered groups, columns are labeled Group 1, Group 2, etc. For named groups using (?<name>…) syntax, the column header shows the name instead of the index — much more readable for complex patterns with many groups. The $<name> reference syntax works in the replace string, so you can restructure matched text using descriptive names rather than fragile position numbers.

Switch to the Replace tab to preview substitution. Enter a replacement string using $1, $2 (numbered group references) or $<name> (named group references) and the result text appears immediately below. This preview matches exactly what JavaScript's string.replace(regex, replacement) would produce, letting you verify the replace logic before putting it in production code. Backreferences like $& (insert entire match) and $ / $'` (pre/post-match) are also supported.

The Presets dropdown loads common real-world patterns with matching sample test strings — click any preset to load the pattern, flags, and test string simultaneously. Use the Quick Reference panel for a reminder of any token syntax: it covers anchors, quantifiers, character classes, groups, lookaheads, lookbehinds, and flag effects. Click the copy icon at the right edge of the pattern bar to copy the full regex in /pattern/flags format for direct use in JavaScript code.

Common Use Cases

Validation Pattern Testing
Test email, URL, phone number, postal code, and date format validation patterns against real input strings before adding them to form validation code. The live highlighting immediately shows which inputs match and which do not, making edge cases visible instantly.
{}
Capture Group Debugging
Build and debug patterns with multiple capture groups for extracting structured data from logs, API responses, config files, and CSV-like text. The capture group table shows every match with each group value in a labelled column — far more readable than console.log output.
Find & Replace Preview
Preview regex find-and-replace operations with group references ($1, $2, $<name>) before using them in code or a text editor. The Replace tab shows the full transformed output immediately, confirming the substitution does exactly what you intended.
Log Parsing & Data Extraction
Build patterns to extract structured data from server logs, error messages, stack traces, and access logs. Named capture groups make log field extraction patterns self-documenting — the group name describes what each captured value represents.
Input Sanitisation Verification
Verify that sanitisation patterns and allow-list regexes catch all edge cases in user-provided strings. Test the pattern against both valid and deliberately malformed inputs to confirm the boundary conditions behave as expected.
Learning Regex Syntax
Use the 10 presets and quick reference panel to understand how specific regex tokens behave interactively. Modify a preset pattern and immediately see how the change affects matches — the fastest way to learn regex lookaheads, lookbehinds, and character class syntax.

Frequently Asked Questions

This tester uses JavaScript's native browser RegExp engine — the same engine that runs in Chrome, Firefox, Safari, and Edge. All patterns must be valid ECMAScript regular expression syntax. PCRE-only features that are not part of ECMAScript — such as \K (keep-out), atomic groups (?>…), possessive quantifiers, and conditional patterns — are not supported. Features introduced in later ECMAScript versions — such as named capture groups (?<name>…), lookbehind assertions (?<=…) and (?<!…), and Unicode property escapes \p{} with the u flag — are supported in all modern browsers.

Wrap the part of your pattern you want to capture in parentheses. For example, the pattern (\d{4})-(\d{2})-(\d{2}) on the string "2024-07-15" creates three capture groups for year, month, and day. The Capture Groups table on the right shows a row for each match, with each group's value in its own column. Named capture groups use (?<name>…) syntax — (?<year>\d{4})-(?<month>\d{2})-(?<day>\d{2}) — and the column headers show "year", "month", "day" instead of 1, 2, 3, making multi-group patterns far easier to read.

Click the Replace tab below the test string area and enter a replacement template. You can reference captured groups using $1, $2 (numbered) or $<name> (named). For example, if your pattern is (\w+)\s(\w+), the replacement $2 $1 swaps the two words. The result preview shows the full output string after all matches are replaced — equivalent to what JavaScript's string.replace(regex, replacement) would produce. The special references $& (full match), $` (text before match), and $' (text after match) are also supported.

The g (global) flag makes the regex return all matches rather than stopping after the first — required for the capture group table to show more than one match. The i (case-insensitive) flag makes letter matching ignore case. The m (multiline) flag changes the meaning of ^ and $ so they match at the start and end of each line rather than the start and end of the whole string. The s (dot-all) flag makes . match newline characters (\n, \r) — by default, . does not match newlines. The u (unicode) flag enables proper Unicode code point matching and allows \p{} Unicode property escapes like \p{Letter} or \p{Emoji}.

The error bar below the pattern input shows the exact browser error message — the same error you would get from new RegExp("yourPattern") in JavaScript. Common causes: unescaped special characters (a literal dot needs \., a literal parenthesis needs \(\)), unclosed groups (parentheses or brackets without a closing match), invalid escape sequences (\e is not a valid escape in JS regex), and invalid quantifier syntax ({2,1} where min > max is illegal). The error message from the browser usually names the specific issue.

The 10 presets are: Email (RFC 5321 local part and domain validation), URL (http/https URL with optional path and query string), IPv4 (four octets, each 0–255), Hex Color (3-digit and 6-digit with optional #), ISO 8601 Date (YYYY-MM-DD format), US Phone (various formats with optional country code), HTML Tag (opening tags with optional attributes), JWT (three Base64URL segments separated by dots), Markdown Bold (text and __text__), and CSS Class (valid CSS identifier starting with a letter or underscore). Each preset loads the pattern, appropriate flags, and a sample test string that demonstrates the expected matches.

Lookahead (?=…) asserts that a position is followed by the given pattern without consuming characters — \d+(?= dollars) matches numbers followed by " dollars" but does not include " dollars" in the match. Negative lookahead (?!…) asserts the position is NOT followed by the pattern. Lookbehind (?<=…) asserts the position is preceded by a pattern — (?<=\$)\d+ matches digits preceded by a $ sign. Negative lookbehind (?<!…) asserts the position is NOT preceded by the pattern. Both lookbehind types are supported in all modern browsers as of ES2018.

Yes — paste any multiline text into the test string area. By default, the dot (.) does not match newlines and ^ / $ match only the start and end of the entire string. Enable the m (multiline) flag to make ^ and $ match at the beginning and end of each line. Enable the s (dot-all) flag to make . match newline characters too. Both flags can be combined — for example, patterns that need to match content that spans multiple lines often need both m and s simultaneously.

Yes — click the copy icon at the right edge of the pattern input bar. It copies the pattern in /pattern/flags format — for example /^\d{4}-\d{2}-\d{2}$/gm — ready to paste directly into JavaScript code. If you need the pattern as a string for new RegExp(pattern, flags), omit the surrounding slashes and use the flags string separately.

There is no imposed limit on the test string length or the number of matches. The tool runs entirely in your browser using the native JavaScript RegExp engine, so performance is governed by browser regex limits. For very long test strings with pathological backtracking patterns (known as ReDoS — Regular Expression Denial of Service), the browser may freeze momentarily. This is a JavaScript engine characteristic, not a limit of this tool. Using possessive quantifiers or atomic groups (not available in JS regex) would prevent this — the practical mitigation in JS is to avoid ambiguous nested quantifiers like (a+)+.