</>CodeScrub

Regex Tester & Explainer

Write a pattern. See matches highlighted. Understand every token.

Enter a pattern to start matchingJavaScript / ECMAScript regex
Test String
Matches0 matches

Enter a pattern above to start matching.

Pattern Explanation

Enter a pattern above to see a token-by-token breakdown.

Common Patterns
Regex Cheatsheet

Characters

.Any character except newline
\dDigit (0-9)
\DNon-digit
\wWord character (a-z, A-Z, 0-9, _)
\WNon-word character
\sWhitespace
\SNon-whitespace

Quantifiers

*0 or more
+1 or more
?0 or 1 (optional)
{n}Exactly n
{n,}n or more
{n,m}Between n and m
*? +?Non-greedy versions

Anchors & Groups

^Start of string
$End of string
\bWord boundary
(...)Capture group
(?:...)Non-capturing group
(?=...)Positive lookahead
(?!...)Negative lookahead
a|ba OR b
[abc]Any of a, b, c
[^abc]Not a, b, or c
[a-z]Range a to z
Ad space · regex-tester-mid

What Is a Regular Expression?

A regular expression — usually shortened to regex — is a compact pattern used to match text. Developers reach for regex for validation (emails, phone numbers, URLs), search-and-replace, parsing log lines, and extracting structured data from messy strings. The syntax is powerful but notoriously hard to read; this tool exists to make it transparent: every token is explained, every match is highlighted.

How to Use This Regex Tester

  1. Enter your pattern (without the surrounding / slashes — those are just for show).
  2. Toggle the flags you need. Hover any flag to see what it does.
  3. Paste the text you want to test against into the left panel.
  4. Review the highlighted matches, capture groups, and the token-by-token breakdown. Everything runs in your browser — no data leaves the page.

Understanding Regex Flags

  • g (global) — find all matches, not just the first.
  • i (case-insensitive) — treat uppercase and lowercase as the same.
  • m (multiline) — make ^ and $ match line boundaries, not just string boundaries.
  • s (dotall) — make . match newline characters too.
  • u (unicode) — enable full Unicode support.

Common Regex Patterns

What it matchesPattern
Email address[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,}
URLhttps?://...
US phone number\(?\d{3}\)?[-.\s]?\d{3}[-.\s]?\d{4}
IPv4 address\b\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}\b
Date (YYYY-MM-DD)\d{4}-(0[1-9]|1[0-2])-(0[1-9]|[12]\d|3[01])
Hex color#([0-9a-fA-F]{3}|[0-9a-fA-F]{6})\b
HTML tag</?([a-zA-Z][a-zA-Z0-9]*)\b[^>]*>
Whitespace trim^\s+|\s+$

Privacy & Security

Your regex patterns and test data never leave your browser. CodeScrub runs entirely client-side — nothing is sent to any server, stored, or logged.