X Xerobit

Regex Tester

Test regular expressions with live match highlighting. Inspect capture groups, preview replacements, and use preset patterns for common needs. Uses your browser's native JavaScript regex engine — same one you'd use in code.

 
Replace preview (optional)
 
Matches with groups
Ready. Edit pattern or test string.

How to use the regex tester

  1. Enter your pattern between the slashes at the top. Flags (g, i, m, s, u, y) go in the second input.
  2. Type or paste a test string on the left. Matches highlight live.
  3. Inspect capture groups in the "Matches with groups" list — $0 is the whole match, $1+ are the groups.
  4. Use the Replace input to preview a substitution. Supports $1, $2, and $&.
  5. Dropdown presets give you a starting pattern for email, URL, IPv4, UUID, ISO date, phone, hex color.

JavaScript regex flags — what they do

Catastrophic backtracking — the regex that kills your server

Patterns like (a+)+b can blow up exponentially on input like aaaaaaaaaaaaaaaaaaaaaaaaaaX. The engine tries every split of the as before giving up. One user-submitted regex on your server is a denial-of-service away.

Defenses:

Named capture groups

Use (?<name>...) to name a group. Access in replacement with $<name> and in code via match.groups.name. Much more maintainable than numeric groups once you have more than two.

Common regex patterns reference

NamePatternMatchesTest string
Email[a-zA-Z0-9._%+\-]+@[a-zA-Z0-9.\-]+\.[a-zA-Z]{2,}Common addressesuser+tag@example.com
URLhttps?://[^\s/$.?#].[^\s]*http/https URLshttps://example.com/path?q=1
IPv4(?:\d{1,3}\.)\{3}\d{1,3}IP addresses192.168.1.100
UUID[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}UUID v4550e8400-e29b-41d4-a716-446655440000
ISO date\d{4}-\d{2}-\d{2}YYYY-MM-DD2026-05-13
Phone (US)(?:\+1\s?)?(?:\(\d{3}\)|\d{3})[\s\-]?\d{3}[\s\-]?\d{4}US phone numbers(555) 867-5309
Hex color#[0-9a-fA-F]{3,6}CSS hex colors#1a2b3c
Slug[a-z0-9]+(?:-[a-z0-9]+)*URL-friendly slugmy-blog-post-title

Lookahead and lookbehind

Lookarounds match a position without consuming characters — they're zero-width assertions. JavaScript supports all four types:

A common use: extract values without the surrounding delimiter — (?<="title":")[^"]+ pulls the title string value from a JSON fragment.

Quantifiers quick reference

QuantifierMeaningExample
*0 or more (greedy)a* matches "", "a", "aaa"
+1 or more (greedy)a+ requires at least one "a"
?0 or 1 (optional)colou?r matches "color" and "colour"
{n}Exactly n times\d{4} matches exactly 4 digits
{n,}n or more times\w{3,} matches 3+ word chars
{n,m}Between n and m times\d{2,4} matches 2 to 4 digits
*? / +?Lazy (minimal match)<.+?> matches one tag, not all tags

Greedy quantifiers expand as far as possible and then backtrack. Lazy quantifiers (? suffix) shrink to the minimum possible match. When parsing HTML-like structures, lazy is almost always what you want.

Regex performance tips

FAQ

Does this match PCRE or JavaScript flavor?

JavaScript. This tool uses your browser's native RegExp engine, so results match exactly what your Node.js, Deno, or browser code will produce. PCRE has features JS lacks: atomic groups, possessive quantifiers, some advanced lookbehind forms, and the \K reset. If your regex uses those and you're targeting Node.js, you'll need a PCRE-compatible library like re2 or reconsider your approach.

Can I test with large inputs?

Yes, but the highlighted matches are capped at 200 visible entries to keep the UI responsive. Matching itself handles up to 10,000 match iterations before safety-cutting. For testing against very large files (multi-MB logs), the browser handles input up to several MB but UI highlighting may lag — reduce the test string to a representative sample.

Is anything sent to a server?

No. Everything runs in your browser. Your regex patterns and test strings never leave your machine.

Why does my valid regex fail when I paste it into code?

Two common causes: first, missing flags — this tool defaults to g (global), but if you paste the pattern into code without adding the same flags, behavior differs. Second, escaping differences — in a JavaScript regex literal (/pattern/) a backslash is literal: /\d/. In a string passed to new RegExp(str), backslashes must be doubled: new RegExp("\\d"). A pattern that works in this tester (which uses regex literals) may fail in new RegExp() if you forget to double the backslashes.

Related tools

Related articles

Pillar

Part of Dev Productivity — regex, cron, timestamps, HTTP, color, word counter, aspect ratio, case.


Written by Mian Ali Khalid. Last updated 2026-05-13.