Regex Tester
Inspect JavaScript regex matches, preview replacements, and download repeatable test cases.
Enter a pattern to see results.
Runs locally in your browser. Nothing is uploaded or sent to a server.
Enter a pattern in Regular Expression and paste a Test String to see highlighted JavaScript regex matches and capture groups. Choose from six flags, preview substitutions in Replace, or check expected results in Tests with an optional whole-string requirement. The tool retains the first 500 matches and counts the total, with details for the first 20. Export matches as JSON or CSV, download test cases, or copy code with static engine compatibility warnings. Matching runs on-device.
Updated
Related Tools
JSON Formatter
Beautify or minify JSON, inspect its structure, and copy or download the result in your browser.
developer-toolsJSON Validator
Check JSON as you type, locate syntax errors, and inspect duplicate keys, key counts and nesting depth.
developer-toolsBase64 Encode / Decode
Convert text or files, repair Base64 padding, choose charsets, and process separate lines locally.
developer-toolsURL Encode / Decode
Encode values, decode URL layers, or edit query parameters with four formats and line-by-line conversion.
developer-toolsCron Expression Parser
Explain Standard, Quartz, and AWS schedules with field details and up to eight local and UTC run times.
developer-toolsCode to Image
Style code with line highlights, diff colors and custom backgrounds; export PNG, JPG or text-based SVG.
How do you test a regex and inspect its capture groups?
Enter ([A-Z]+)-(\d{3}) in Regular Expression, leave g enabled, and paste Items AB-042 and CD-317. into Test String. Match mode finds two product codes. Enter only the pattern: the slashes around the input are already supplied by the interface, and flags have separate toggles.
| Match | Index | Group 1 | Group 2 |
|---|---|---|---|
| AB-042 | 6 | AB | 042 |
| CD-317 | 17 | CD | 317 |
Indexes start at zero. Switch to Replace and enter $2/$1 in Replacement. Replace Output becomes Items 042/AB and 317/CD., with two replacements. Disable g to change only the first code. The numeric capture remains text, preserving its leading zero. The pattern finds code-shaped substrings rather than checking an entire inventory record.
What is a regular expression useful for?
A regular expression describes text to find, extract, or replace. Regular expressions grew from formal language theory into text-editor search and programming-language APIs. Character classes specify allowed characters, quantifiers specify repetition, and parentheses capture parts of a match. Use regex for log fields, identifiers, simple input checks, and substitutions. Use a structured parser when nested document syntax or semantic validation is the real task.
This tester combines matching, replacement previews, expected-result test rows, token explanations, and exports. Open Explain this pattern for a token breakdown, or insert syntax from Quick Reference. The explanation helps you read the expression; passing examples still provide the evidence that it behaves as intended.
Which regex flags should you enable?
The tool starts with g selected. ECMAScript defines the flag behavior; the browser’s RegExp implementation executes it. Keep your flags consistent when moving a pattern into application code, especially when comparing a single match with an extraction across an entire text.
| Flag | Effect | When it helps |
|---|---|---|
| g | Continue after each match | Find or replace every occurrence |
| i | Ignore case | Match differently capitalized text |
| m | Make ^ and $ line boundaries | Search individual lines |
| s | Let . match line terminators | Search across newlines |
| u | Enable Unicode-aware parsing and matching | Use Unicode property escapes |
| v | Enable Unicode sets and string properties | Use extended character-set syntax |
The u and v flags are mutually exclusive: selecting one deselects the other. Multiline does not make dot match newlines; dotall does. Unsupported syntax produces a browser syntax error rather than silently changing the regex flavor.
Which preset patterns are available, and what do they validate?
Pattern Library contains 20 presets across Common, Dates & Times, Web & Code, and Identifiers. These include Email, URL, IPv4, IPv6, Phone (E.164), ISO Date, Time (24h), Hex Color, Markdown Link, Slug, UUID, JWT, and Semver. Selecting a preset replaces the pattern while leaving your chosen flags unchanged.
Treat presets as starting points. ISO Date restricts months to 01–12 and days to 01–31, but does not check month lengths or leap years. IPv4 restricts octets to 0–255; IPv6 covers eight explicit hexadecimal groups rather than compressed forms. Email and URL patterns find text shapes, not reachable destinations. Phone (E.164) permits an optional plus and 2–15 digits beginning with a nonzero digit; it does not verify allocation. JWT matches a token-shaped string without verifying its signature.
Why does a regex match too much, too little, or nothing?
Start with flags and escaping. Without g, only the first match is collected. A dot means a wildcard, while \. means a literal dot. Enter a single backslash in the pattern field; double escaping belongs to contexts such as JavaScript string literals. Greedy .* consumes as much as possible, while lazy .*? tries shorter matches first.
Parentheses capture values, (?:...) groups without capturing, and (?<name>...) names a capture. Match Details displays captured values alongside each displayed match. Positions and lengths use JavaScript UTF-16 code units, so an emoji can occupy two positions. For zero-length global matches, the collector explicitly advances its position, using code-point width under u or v, to avoid repeating the same empty match forever.
How do you turn examples into repeatable regex tests?
Open Tests, click Add test string, and choose Should match or Should not match for each row. The summary reports how many expectations pass. Include ordinary inputs, near misses, empty strings, and unwanted prefixes or suffixes. Partial matching is the default; enable Match the whole string (otherwise a partial match counts) for complete-input validation.
Each test uses a fresh expression without global or sticky state. Whole-string mode adds boundary assertions that remain strict with multiline enabled. Choose Test framework and Download tests to save regex.test.ts for Vitest or regex.test.js for Jest. These files reproduce the row expectations and whole-string setting, rather than recording extracted capture values.
What are the match limits and backtracking protections?
The collector retains the first 500 matches while counting the total if execution finishes. Highlighting and match export use that retained list; Match Details shows the first 20. A larger reported total therefore does not mean every match is present in a downloaded file. Replacement uses the full input rather than the retained list.
Matching normally runs in a Web Worker with a 1,000 ms timeout. If workers are unavailable or cannot be created, execution falls back to the main thread without that timeout protection. Avoid nested overlapping quantifiers such as (a+)+$, especially on long near-matching inputs. A timeout indicates unfinished work, not a definitive no-match result.
How do code, match exports, and sharing work?
Expand Copy as code and export matches to choose JavaScript, Python, PHP, Go, Java, or .NET. Compatibility checks flag known syntax differences without executing another engine. Python and Go exports rewrite named groups. Common flag mappings include i to Python re.I, PHP i, Go (?i), and Java Pattern.CASE_INSENSITIVE. Unsupported flag notes accompany snippets; Go warnings cover lookarounds and backreferences.
JSON export includes index, matched text, and captures; CSV uses index and match columns plus capture columns. Matching and replacement run on-device. Inputs are also encoded in the URL fragment so reloads and Share can restore work. Encoding is reversible, so review the included text before distributing a link. Use JSON Formatter to inspect exported JSON or JSON Validator to check an edited export.
How to Use Regex Tester
-
Regular Expression
Enter the pattern without surrounding slashes. Toggle g, i, m, s, u, or v; g starts enabled. Use Pattern Library for a preset or Quick Reference to insert a token.
-
Test String
Paste sample text in Test String. In Match, review Highlighted Matches, the total count, and Match Details. Invalid patterns display a syntax error.
-
Replace
Select Replace and enter Replacement using $1, $2, or $<name> references. Review Replace Output and use Copy to copy the result.
-
Tests
Select Tests, use Add test string, and choose Should match or Should not match for each row. Enable Match the whole string (otherwise a partial match counts) for validation. Choose Test framework and click Download tests.
-
Copy as code and export matches
Return to Match, expand Copy as code and export matches, select Language, and review Engine compatibility (static checks). Use Copy as code, Download JSON, or Download CSV. Share copies a permalink containing the current inputs.