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
- Enter your pattern (without the surrounding
/slashes — those are just for show). - Toggle the flags you need. Hover any flag to see what it does.
- Paste the text you want to test against into the left panel.
- 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 matches | Pattern |
|---|---|
| Email address | [a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,} |
| URL | https?://... |
| 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.