🧰 ToolPicoAll Tools →

Regex Tester

Test your regular expression live: match highlighting, capture groups, a find & replace preview, a step-by-step pattern explainer, and a code generator for four languages — plus ready-made templates for phone numbers, email, ZIP codes, and more.

🔒 100% in your browser 22 ready-made templates Groups + Named groups ⚠️ ReDoS quick-check Updated: Jul 28, 2026
Wrapping your pattern in /…/ is fine — the slashes are stripped automatically. Just the pattern itself is required. Hover a row on the Explain tab to highlight the matching piece here.
Checking…
Matches are highlighted live (purple/pink). If the pattern is invalid, an error box appears above.

Copy every match — or a single capture group — as plain text: one per line, comma-separated, or with a custom separator. Download the full result, including positions and groups, as CSV. Great for pulling every email, phone number, or date out of a block of text.

Reference capture groups with $1, $2… or named groups with $<name>. If the "g" flag is off, only the first match is replaced.
Piece-by-piece breakdown of your pattern
PieceMeaning
For a general reference of every symbol, see the Reference tables section below.

        
      

Validate your pattern against real examples: each line is one test. Lines under "Should match" must match the pattern; lines under "Should NOT match" must not. Ideal for hardening a validation pattern (like a phone number or email check) against several examples at once. Tip: use ^ and $ anchors in your pattern for full-line validation.

Only the pattern and flags are added to the shareable link; your test string (which may contain personal data) is never included.
Quick answer A regex tester runs the pattern you write against the text you provide and instantly highlights what matches. This tool highlights matches live, lists capture groups and named groups, previews find-and-replace, explains the pattern piece by piece, and generates equivalent code for JavaScript, Python, PHP, and Java — entirely in your browser, with nothing sent to a server.
22Ready-made templates
5Flags (g,i,m,s,u)
4Code languages
100%Client-side
⚙️ Accuracy & engine note: This tool uses the browser's built-in ECMAScript (JavaScript) regex engine. PCRE (PHP), Python's re, and Java's regex engine share most syntax but can differ slightly on advanced features (like atomic groups or possessive quantifiers) — test the "Generate Code" output separately in your target language. The credit card and IBAN templates check format only; they do not verify checksums.

What is regex, and how do you test one?

A complete guide — syntax, capture groups, find & replace, and flags — explained and made citable.

A regular expression (regex, for short) is a special syntax used to describe a pattern within text. For example, \d{4} means "four digits in a row," and [A-Z][a-z]+ means "a word that starts with a capital letter." Regex is used for form validation (phone numbers, email addresses, credit card formats), log file analysis, search-and-replace, and data extraction — and nearly every programming language, including JavaScript, Python, PHP, and Java, supports very similar syntax.

Why does testing a regex pattern matter?

Quick answerRegex syntax is dense and easy to get wrong — forgetting to escape a character (using . instead of \., for example) can lead to unexpected matches. Testing your pattern live against real sample data, and visually confirming which parts actually match, is the most reliable way to catch mistakes before a bad pattern ships to production.

What is a capture group?

Quick answerA section wrapped in parentheses, like (abc), forms a "capture group" and makes that part of the match separately accessible. (?:abc) is a non-capturing group — it groups without being numbered. (?<name>abc) assigns a name to a group (a named group); the result can then be accessed by number or by name.
  • Numbered group(\d{2})-(\d{2}): in "12-34," group 1 = "12," group 2 = "34."
  • Named group(?<year>\d{4}): accessible in the result as groups.year.
  • Non-capturing group(?:abc)+: groups repeated "abc" without numbering it.

How does find & replace work?

Quick answerIn a find-and-replace operation, the parts matched by the regex are swapped for another string; capture groups are referenced with $1, $2… or, for named groups, $<name>. For example, running (\d{4})-(\d{2})-(\d{2}) against replacement $2/$3/$1 turns "2026-07-19" into "07/19/2026." If the "g" flag isn't set, only the first match is replaced — try it live in the "Replace" tab above.

What do regex flags do?

Quick answerg finds every match (without it, only the first); i turns off case sensitivity; m makes ^/$ anchors match the start/end of every line, not just the whole string; s (dotall) lets . match newlines too; and u interprets the pattern by Unicode code points. Flags are added as a separate option, not appended inside the pattern itself.

Common regex symbols (quick summary)

Quick reference — see the full Reference section below for everything
SymbolMeaningExample
\dDigit (0-9)\d{4} → "2026"
\wWord character (letter/digit/_)\w+ → "hello_123"
\sWhitespace (space/tab/newline)\s+ → " "
^ $Start and end of text/line^abc$ → exactly "abc"
* + ? {n,m}Quantifiers (repetition)a{2,4} → "aa".."aaaa"
(...) (?:...) (?<name>...)Capture / non-capturing / named group(\d+)-(\d+)

Regex reference tables & cheat sheet

Character classes, quantifiers, groups & flags, and ready-made common formats — a complete, citable reference.

Character classes and shorthand
SymbolMeaning
.Any character except newline (with the "s" flag, newline included)
\d / \DDigit / non-digit character
\w / \WWord character (letter/digit/_) / non-word character
\s / \SWhitespace character / non-whitespace character
[abc]One of a, b, or c
[^abc]Any character EXCEPT a, b, c
[a-z0-9]Lowercase letter a-z OR digit 0-9
\b / \BWord boundary / non-word-boundary position
Quantifiers (repetition)
SymbolMeaning
*0 or more repetitions (greedy)
+1 or more repetitions (greedy)
?0 or 1 repetition (optional)
{n}Exactly n repetitions
{n,}At least n repetitions
{n,m}Between n and m repetitions
*? +? ?? {n,m}?Lazy version — tries to match as FEW repetitions as possible

Greedy is the default: it tries to match the longest possible string. Adding ? at the end makes it lazy (it tries the shortest match instead).

Groups, lookarounds, and flags
SymbolMeaning
(abc)Capture group
(?:abc)Non-capturing group
(?<name>abc)Named capture group
(?=abc)Positive lookahead
(?!abc)Negative lookahead
(?<=abc)Positive lookbehind
(?<!abc)Negative lookbehind
a|ba OR b (alternation)
g i m s uFlags: global, case-insensitive, multiline, dotall, unicode
Ready-made common-format patterns (format check only)
FormatRegex
US Phone Number^(?:\+1|1)?\s?\(?\d{3}\)?[\s.-]?\d{3}[\s.-]?\d{4}$
Email Address^[\w.+-]+@[\w-]+\.[a-zA-Z]{2,}$
ZIP Code (US)^\d{5}(-\d{4})?$
IBAN (international)^[A-Z]{2}\d{2}[A-Z0-9]{10,30}$
Credit Card Number^\d{4}[\s-]?\d{4}[\s-]?\d{4}[\s-]?\d{4}$
Hex Color Code^#(?:[A-Fa-f0-9]{6}|[A-Fa-f0-9]{3})$
Strong Password^(?=.*[a-z])(?=.*[A-Z])(?=.*\d)(?=.*[^\da-zA-Z]).{8,}$
URL^(https?:\/\/)?([\w-]+\.)+[a-zA-Z]{2,}(:\d+)?(\/[^\s]*)?$
IPv4 Address^(?:(?:25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)\.){3}(?:25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)$
IPv6 Address^([0-9a-fA-F]{1,4}:){7}[0-9a-fA-F]{1,4}$
UUID / GUID^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}$
HTML Tag<\/?[a-zA-Z][a-zA-Z0-9]*(?:\s+[^<>]*)?\/?>
MAC Address^(?:[0-9A-Fa-f]{2}:){5}[0-9A-Fa-f]{2}$
US SSN^(?!000|666|9\d\d)\d{3}-(?!00)\d{2}-(?!0000)\d{4}$
US Date (MM/DD/YYYY)^(0[1-9]|1[0-2])\/(0[1-9]|[12]\d|3[01])\/\d{4}$
ISO Date (YYYY-MM-DD)^\d{4}-(0[1-9]|1[0-2])-(0[1-9]|[12]\d|3[01])$
Time (HH:MM, 24h)^([01]\d|2[0-3]):[0-5]\d$
Slug / URL-safe String^[a-z0-9]+(?:-[a-z0-9]+)*$
Hashtag#[A-Za-z0-9_]+
YouTube Video ID(?:youtu\.be\/|youtube\.com\/(?:watch\?v=|embed\/|shorts\/))([\w-]{11})
File Extension\.([a-zA-Z0-9]+)$
HTML Comment<!--[\s\S]*?-->

These patterns check format (length and character set) only — they don't verify checksums (e.g. the Luhn algorithm for card numbers) or confirm a number is actually issued or active.

Add this regex tester to your site (embed code)

Embed the regex tester on your own website for free. Copy the code below into your HTML — the tool runs in a simplified view and links back to this page as its source.

The embedded tool has a fixed layout; adjust the height value to fit your site. No ads or personal data — everything runs client-side.

Regex terms glossary

Short definitions of the core concepts used in regular expressions.

PatternThe regex text itself that defines what to match.
FlagAn extra letter that changes how the pattern behaves: g, i, m, s, u, for example.
Capture groupA part of the pattern in parentheses (...) whose matched text becomes separately accessible.
Named groupA capture group given a name with (?<name>...); accessed by that name in the result.
Greedy / LazyA greedy quantifier tries to match as much as possible; a lazy one (with a trailing ?) tries to match as little as possible.
BackreferenceReferring back to an earlier capture group within the pattern, using \1, \2, etc.
Anchor^ and $ — they mark the start and end of the text/line without consuming any characters.
Lookahead / LookbehindChecks whether a pattern exists before or after a position, without including it in the match.
MetacharacterA character with special meaning in regex: . * + ? ^ $ ( ) [ ] { } | \.
EscapePutting a \ before a metacharacter to match it literally, e.g. \..
Replace / SubstitutionSwapping the matched text for another string, referencing groups with $1, etc.
Global (g) matchFinding every match in the text, not just the first one.

In-depth guides

Detailed answers to the most commonly asked regex questions.

How do you validate a credit card number format with regex, and why isn't that enough on its own?

The pattern ^\d{4}[\s-]?\d{4}[\s-]?\d{4}[\s-]?\d{4}$ checks the format of a card number: four groups of four digits, with an optional space or dash between them. But a genuinely valid card number also has to pass the Luhn algorithm — a checksum calculation performed by doubling every second digit (from the right), summing the digits of the results, and checking that the total is divisible by 10. That calculation is arithmetic, not pattern matching, so a regex on its own can't perform it.

This is why production form validation typically uses a two-step approach: a fast regex filter for format first, then a Luhn check (or a payment provider's own validation) for the number itself. The same principle applies to other checksum-based identifiers, such as ISBNs and some national ID formats — regex confirms the shape; a separate algorithm confirms the number is real.

How does the US phone number regex handle different formatting styles?

In ^(?:\+1|1)?\s?\(?\d{3}\)?[\s.-]?\d{3}[\s.-]?\d{4}$, (?:\+1|1)? makes the country code optional, \(?...\)? makes the parentheses around the area code optional, and each [\s.-]? makes a space, dot, or dash between digit groups optional. As a result, "(555) 123-4567," "555.123.4567," "+1 555 123 4567," and "5551234567" all match the same single pattern.

Note this pattern targets typical 10-digit US numbers; it won't validate international numbers in other formats, and it doesn't check whether an area code actually exists. Click the "US Phone Number" template above to try it live.

Greedy vs. lazy quantifiers — what's the difference?

By default, quantifiers like *, +, and {n,m} are greedy: they try to match as many characters as possible. For example, the pattern <.+> applied to "<b>text</b>" matches EVERYTHING from the very first < to the very last > as a single match — usually not what you want.

Adding a ? after the quantifier (<.+?>) makes it lazy, so it tries to match as FEW characters as possible: on the same text, it finds two separate matches, "<b>" and then "</b>." When working with nested delimiters like HTML/XML tags, a lazy quantifier usually gives you the result you expect.

Frequently asked questions

How do you test a regex pattern?
Write your regex pattern into a testing tool and enter the text you want to check it against to see matches live. In this tool, after entering your pattern and flags (g, i, m, s, u), matching portions of the text are automatically highlighted in color; capture groups, position information, and named groups are listed in a separate table. You can refine your pattern through quick trial and error.
What is a regular expression (regex)?
A regular expression (regex) is a special syntax used to define a specific pattern within text. For example, the pattern \d{11} means "11 digits in a row." Regex is widely used for form validation (email, phone number, credit card format), text search-and-replace, log analysis, and data extraction, and is supported with very similar syntax in almost every programming language (JavaScript, Python, PHP, Java).
How do you write a regex for a US phone number?
The pattern ^(?:\+1|1)?\s?\(?\d{3}\)?[\s.-]?\d{3}[\s.-]?\d{4}$ matches a 10-digit US phone number with an optional +1/1 country code, optional parentheses around the area code, and optional spaces, dots, or dashes between groups. That means "(555) 123-4567," "555.123.4567," and "+1 555 123 4567" can all match with the same pattern. This pattern only checks common formatting — it doesn't verify that an area code is actually assigned.
What's an example email regex?
A practical email validation pattern is ^[\w.+-]+@[\w-]+\.[a-zA-Z]{2,}$: it looks for letters, digits, underscore, dot, plus, or dash in the username, an @ sign, a domain name, and an extension of at least two letters. A fully RFC 5322-compliant email regex is far more complex; in practice, this simplified pattern is good enough for most form validation.
How do you validate a credit card number format with regex — and is that enough?
The pattern ^\d{4}[\s-]?\d{4}[\s-]?\d{4}[\s-]?\d{4}$ checks that a card number is four groups of four digits, optionally separated by spaces or dashes. That's a format check only — a genuinely valid card number also needs to pass the Luhn checksum algorithm, a digit-by-digit arithmetic calculation that a regex alone cannot perform. In practice, use a two-step approach: a quick regex format filter, followed by a Luhn check in your application code.
Is an online regex tester safe to use?
In this tool, your regex pattern and test string are processed entirely in your browser (client-side JavaScript); nothing is sent to a server, saved, or logged. When you build a shareable link, only the pattern and flags are added to the URL — your test string, which may contain personal data, is never included in the link.
What is a capture group in regex?
A section wrapped in parentheses, like (abc), forms a "capture group" and makes the matched text of that section separately accessible; for example, the pattern (\d{2})-(\d{2}) applied to "12-34" captures group 1 = "12" and group 2 = "34." Groups can be named with (?<name>...) syntax (a named group); (?:...) groups without capturing at all.
How does regex find-and-replace work?
In a find-and-replace operation, the text matched by the regex is swapped for another string; capture groups are referenced with $1, $2… or, for named groups, with $<name>. For example, running the pattern (\d{4})-(\d{2})-(\d{2}) against the replacement $2/$3/$1 turns "2026-07-19" into "07/19/2026." If the "g" flag isn't checked, only the first match is replaced.
How do I extract all emails or phone numbers from a block of text with regex?
Write your pattern (e.g. [\w.+-]+@[\w-]+\.[a-zA-Z]{2,} for email), turn on the "g" flag, and paste in your text; then, on the "Extract / List" tab, every match is listed as plain text — one per line, comma-separated, or with a custom separator. Use "remove duplicates" to drop repeats, copy the list with one click, or download it as .txt, or as .csv with position and group details included. Tip: don't use ^ and $ anchors if you want to search within a line rather than match the whole line.
How do I test my regex pattern against multiple examples (unit testing)?
Use the "Tests" tab: enter examples that should match your pattern in the "Should match" box, and examples that should NOT match in the "Should NOT match" box, one per line. The tool runs every line against your pattern, compares it to your expectation, and marks each one green (passed) or red (failed), with an "X/Y tests passed" summary at the top. It's ideal for hardening validation patterns like phone numbers or emails against several real examples. Use ^ and $ anchors for full-line validation.
Where do the built-in templates come from, and how often are they updated?
The ready-made templates (US phone, email, ZIP code, IBAN, credit card, hex color, strong password, URL, IPv4/IPv6, UUID, HTML tag, MAC address, US SSN, US/ISO date, time, slug, hashtag, YouTube video ID, file extension, HTML comment) are based on widely accepted format conventions, and — as evergreen structural rules — don't require frequent updates. The matching engine is your browser's built-in ECMAScript regex engine. Last updated: July 28, 2026.
What is ReDoS (catastrophic backtracking), and how does the quick-check work?
ReDoS (Regular expression Denial of Service) happens when a pattern with ambiguous nested or overlapping quantifiers — like (a+)+ or (a|a)* — takes exponentially longer to fail as the input grows, sometimes freezing the page or server for seconds or minutes on a single string. The badge under the pattern field runs your compiled pattern against a few adversarial repeated-character strings of increasing length, entirely in your browser; if any probe takes noticeably longer than expected, it's flagged as "may be slow on certain inputs." This is a best-effort heuristic, not a formal proof — a clean result doesn't guarantee a pattern is completely safe, but a flagged one is worth rewriting (e.g. replacing nested quantifiers with more specific character classes).

Methodology & sources

ToolPico's Regex Tester is an independent, free tool. The matching engine uses the browser's built-in ECMAScript (JavaScript) RegExp implementation directly — no server-side processing or third-party API is required. The 22 ready-made templates (phone, email, ZIP code, IBAN, credit card, hex color, strong password, URL, IPv4/IPv6, UUID, HTML tag, MAC address, US SSN, US/ISO date, time, slug, hashtag, YouTube video ID, file extension, HTML comment) are built on widely accepted format conventions. The ReDoS quick-check badge runs a heuristic, client-side timing probe against adversarial repeated-character inputs — it is not a formal proof of safety.

Sources: ECMA-262 (JavaScript) regular expression syntax reference · ISO 13616 (IBAN structure) · generally accepted US phone number and ZIP code formatting conventions · the Luhn algorithm (ISO/IEC 7812-1) for card-number checksums · OWASP guidance on Regular expression Denial of Service (ReDoS). Last updated: July 28, 2026. Results are for informational and development purposes; combine with algorithmic (checksum) validation for critical data checks.

🔗 Add this tool to your site

Copy the code below into your own site. The tool is free, always up to date, and runs entirely on your page. No sign-up required.

Preview →
⚡ Built with ToolPico · toolpico.com