NattangNattang
BestsellersMarketplaceHire MePortfolio

Code Tools

JSON Formatter

Format, validate and minify JSON data

Regex Tester

Test regular expressions in real-time

Code to Image

Beautiful code screenshots for sharing

Generators

CSS Generator

Box-shadow & gradient builder with live preview

README Generator

Build GitHub README files with ease

Freelance Calculator

Calculate hourly rate for freelancers

Image Tools

Gemini Watermark Remover

Remove Gemini & Nano Banana watermarks

Articles & Guides

Articles

Tutorials, tips & insights

Free Developer Tools

Boost your workflow with our collection of free, open-source developer utilities.

Code editor with a dark theme
A developer's workspace
Explore all tools
Sign In
  1. Home
  2. Tools
  3. Regex Tester & Debugger

Regex Tester & Debugger

Write a pattern, see every match highlighted, and learn what each token does.

  • Free
  • No sign-up
  • Runs in your browser

Updated Oct 2026

//Flags: gi
Flags
158 chars3 lines
Contact us at [email protected] or [email protected] Invalid emails: @missing.com, user@, [email protected] Valid: [email protected], [email protected]
  • [a-zA-Z0-9._%+-]
  • +
  • @
  • [a-zA-Z0-9.-]
  • +
  • \.
  • [a-zA-Z]
  • {2,}

Match Results

4 matches
  1. 1[email protected][14–33]
  2. 2[email protected][37–54]
  3. 3[email protected][110–139]
  4. 4[email protected][141–158]

Regex guide — learn by example

Regular expressions (regex) are patterns used to match text. Press Try it on any example to load it into the tester above.

1Literal Characters — Match Exact Text

The simplest regex matches exact text. Just type the word or phrase you want to find.

  • Find a specific word

    /hello/gi

    Matches the word "hello" regardless of case (i flag). The g flag finds all occurrences, not just the first.

  • Match a phrase with spaces

    /ice cream/g

    Spaces are literal in regex — this matches the exact phrase "ice cream" with the space.

2Character Classes — Match Types of Characters

Use shorthand codes to match categories: \d for digits, \w for word characters, \s for spaces, and . for any character.

  • \d — Match any digit

    /\d+/g

    \d matches any digit [0-9]. The + means "one or more". So \d+ matches sequences of digits like 1234, 2024, 03, 15, 99, 50, 3.

  • \w — Match word characters

    /\w+/g

    \w matches letters, digits, and underscore [a-zA-Z0-9_]. Notice @#$% are NOT matched because they aren't word characters.

  • . (dot) — Match any character

    /c.t/g

    The dot matches ANY single character. So c.t matches cat, cot, cut, c@t, c3t — but not "c t" (space counts!) and not "cart" (too many chars between c and t).

  • \s — Match whitespace

    /\s+/g

    \s matches spaces, tabs (\t), newlines (\n), and other whitespace. \s+ matches one or more whitespace characters in a row.

3Character Sets [...] — Custom Groups

Square brackets let you define custom sets of characters to match. Use [abc] for specific chars, [a-z] for ranges, and [^abc] to negate.

  • [aeiou] — Match vowels only

    /[aeiou]/gi

    Matches any single character that is a, e, i, o, or u. Each vowel is matched individually.

  • [0-9a-fA-F] — Hex digits

    /#[0-9a-fA-F]{3,6}/g

    The range [0-9a-fA-F] matches any hex digit. {3,6} means the hex part must be 3 to 6 characters long.

  • [^...] — Negated set (NOT these characters)

    /[^a-zA-Z\s]/g

    The ^ inside brackets means NOT. This matches anything that is NOT a letter and NOT whitespace — so it finds digits, punctuation, symbols.

4Quantifiers — How Many Times

Control how many times a pattern repeats: * (0+), + (1+), ? (0 or 1), {n} (exact), {n,m} (range).

  • * — Zero or more

    /go*d/g

    o* means zero or more o's. So it matches: gd (0 o's), god (1 o), good (2 o's), goood (3 o's), etc.

  • + — One or more

    /go+d/g

    o+ means one or more o's. Unlike *, it requires at least one o. So "gd" does NOT match, but god, good, goood all do.

  • ? — Optional (zero or one)

    /colou?r/gi

    u? means the u is optional (0 or 1 times). Matches both "color" (American) and "colour" (British) but not "colouur".

  • {n,m} — Specific range

    /\d{2,4}/g

    {2,4} means between 2 and 4 times. \d{2,4} matches 2 to 4 digit sequences. "1" alone doesn't match (too short). "12345" partially matches as "1234".

5Anchors — Position Matching

Anchors don't match characters — they match positions. ^ matches start, $ matches end, \b matches word boundaries.

  • ^ and $ — Start and end of line

    /^Error.*$/gm

    ^ means start of line (with m flag). $ means end of line. Combined, this matches entire lines that START with "Error". The m flag makes ^ and $ work per-line instead of whole-string.

  • \b — Word boundary

    /\bcat\b/gi

    \b marks a word boundary (between a word char and a non-word char). \bcat\b matches "cat" as a whole word — NOT "cat" inside "concatenate" or "category".

6Groups & Capture — Extract Parts

Parentheses () create groups that capture matched text. Use them to extract specific parts from a match.

  • Basic capture groups

    /(\d{4})-(\d{2})-(\d{2})/g

    Each set of parentheses captures a group. Group 1 = year (\d{4}), Group 2 = month (\d{2}), Group 3 = day (\d{2}). Click a match to see groups.

  • Named capture groups

    /(?<protocol>https?)://(?<domain>[\w.-]+)/g

    (?<name>...) creates a named group. Instead of Group 1/2, you get meaningful names like "protocol" and "domain" — much easier to read.

  • Non-capturing groups (?:...)

    /(?:Mr|Mrs|Ms)\.?\s(\w+)/g

    (?:...) groups without capturing. The title alternatives (Mr|Mrs|Ms) are grouped but not captured. Only the name (\w+) is captured as Group 1.

7Alternation — OR Logic

The pipe | means OR — match this pattern OR that pattern.

  • Simple alternation

    /cat|dog|bird/gi

    Matches "cat" OR "dog" OR "bird" anywhere in the text. Simple and powerful for matching alternatives.

  • Alternation with groups

    /(Mon|Tues|Wednes|Thurs|Fri|Satur|Sun)day/g

    Groups + alternation to match all valid day names. The prefix is captured as Group 1. "Funday" doesn't match because "Fun" isn't in the alternatives.

8Lookahead & Lookbehind — Context Matching

Match a position where specific text appears before or after, without including that text in the match.

  • Positive lookahead (?=...)

    /\w+(?=@)/g

    (?=@) means "followed by @" but @ is NOT included in the match. So it captures just the username part before the @.

  • Negative lookahead (?!...)

    /\d+(?!\$|%)/g

    (?!\$|%) means "NOT followed by $ or %". Matches numbers that are NOT dollar amounts or percentages. 300, 400, and 500 match.

  • Positive lookbehind (?<=...)

    /(?<=\$)\d+\.?\d*/g

    (?<=\$) means "preceded by $" but $ is NOT in the match. Captures only the numeric amount after the dollar sign.

9Greedy vs Lazy — Controlling Match Length

By default, quantifiers are greedy (match as much as possible). Add ? to make them lazy (match as little as possible).

  • Greedy .* — matches too much

    /<.+>/g

    Greedy .+ matches as MUCH as possible. It matches from the first < all the way to the LAST >, swallowing everything in between as one big match.

  • Lazy .+? — matches the minimum

    /<.+?>/g

    Adding ? makes it lazy — .+? matches as LITTLE as possible. Now each HTML tag (<b>, </b>, <i>, </i>) is matched individually.

Practical Examples — Real-World Patterns

Combine everything you've learned into useful real-world patterns.

  • Extract image filenames

    /[\w-]+\.(jpg|png|gif|svg|webp)/gi

    Matches filenames ending with common image extensions. [\w-]+ matches the name part, \. matches the literal dot, and (jpg|png|...) matches image extensions.

  • Validate time format (HH:MM)

    /^([01]\d|2[0-3]):[0-5]\d$/gm

    Validates 24-hour time. Hours: 00-23 ([01]\d covers 00-19, 2[0-3] covers 20-23). Minutes: 00-59 ([0-5]\d). Invalid entries like 24:00, 12:60, and 7:30 don't match.

  • Find duplicate words

    /\b(\w+)\s+\1\b/gi

    \b(\w+) captures a word, \s+ matches spaces, \1 is a back-reference that matches the SAME text as Group 1. Finds repeated words like "is is" and "the the".

  • CSS hex color in code

    /#(?:[0-9a-fA-F]{3}){1,2}\b/g

    Matches 3 or 6 digit hex colors. (?:[0-9a-fA-F]{3}) matches 3 hex chars, {1,2} means this group appears 1 or 2 times (for #333 or #FF5733).

What is it?

A regex tester lets you run a regular expression against sample text and see exactly what it matches. This one uses your browser's JavaScript RegExp engine, highlights matches as you type, lists numbered and named capture groups, explains the pattern token by token, and previews replacements with $1 or $<name>. Nothing is sent to a server.

How to use

  1. 1Type a pattern into the Pattern field, or pick one from Patterns.
  2. 2Toggle the flags you need: g, i, m, s or u.
  3. 3Paste text into Test String and read the highlighted matches and capture groups.
  4. 4Switch to Replace and enter a replacement string to preview the output.
  5. 5Copy the regex as /pattern/flags when it works.

Frequently asked questions

Is my text sent to a server?

No. Patterns and test strings are evaluated with the RegExp engine built into your browser, and the tool makes no network requests with your data.

Which regex flavor does this use?

JavaScript (ECMAScript), the same engine your browser and Node.js run. Patterns from PCRE or Python mostly work, but features like possessive quantifiers, atomic groups and inline modifiers such as (?i) are not supported.

Does this support lookbehind?

Yes. Positive (?<=...) and negative (?<!...) lookbehind work in every current browser, including Safari 16.4 and later. Lookahead (?=...) and (?!...) work too.

Why does my regex only find the first match?

The g (global) flag is off. Without it, JavaScript stops at the first match; turn g on to find all of them.

What is the difference between greedy and lazy quantifiers?

Greedy quantifiers like .* match as much text as possible, then back off; lazy ones like .*? match as little as possible. On <b>a</b><b>c</b>, <b>.*</b> matches the whole line while <b>.*?</b> matches each tag pair separately.

Which flags are available?

The toggles cover g (global), i (case-insensitive), m (multiline), s (dotAll) and u (unicode). The y (sticky), d (indices) and v (unicodeSets) flags are not offered.

Can a bad pattern freeze my browser?

With g on, the tool stops collecting matches after 200 ms or 5,000 results and shows a warning. A single catastrophic match cannot be interrupted mid-run, so avoid nested quantifiers like (a+)+ on long input.

How do I use capture groups in a replacement?

Switch to Replace and reference groups with $1, $2 and so on, or $<name> for named groups; $& inserts the whole match.

Features

Live highlighting
Matches are highlighted in the test string about 150 ms after you stop typing, each in its own color.
Capture groups
Each match lists its position plus every numbered and named group, such as (?<year>\d{4}).
Pattern explanation
The Explanation panel breaks the pattern into tokens and describes each one in plain language.
Replace mode
Previews String.replace output with $&, $1–$9 and $<name> substitutions.
8 presets
Email, URL, phone number, IPv4, HTML tags, ISO date, hex color and password strength, each with sample text.
Cheatsheet and tutorial
A clickable cheatsheet inserts tokens into the pattern, and a 10-section tutorial loads each example with Try it.
Safety limits
Patterns are capped at 1,000 characters, test text at 100,000, results at 5,000 matches, and global matching stops after 200 ms.

Related tools

  • JSON Formatter & ValidatorFormat, validate, and minify JSON with auto-fix, tree view, key sorting, and file upload/download. Runs entirely in the browser.
  • Code to ImageTurn code snippets into shareable images with syntax highlighting, themes, window chrome, and PNG/SVG export.
  • CSS Box-Shadow & Gradient GeneratorBuild multi-layer box-shadows and linear/radial/conic gradients with a live preview and copy-ready CSS.
NattangNattang

Beautifully crafted digital products and free tools. Built in Thailand, made for creators worldwide.

FAQ

How do I get my files? After purchase, download links are sent to your email instantly.

Can I get a refund? Due to the digital nature of our products, all sales are final.

Secure Payments

Visa
Mastercard
Stripe

All transactions are encrypted and secure.

© 2026 Nattang. All rights reserved.
AboutPrivacy PolicyCookie PolicyTerms of Service