Nattang
BestsellersMarketplaceArticles

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

Free Developer Tools

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

Code editor dark theme
Developer workspace
Explore all tools
Sign In

Regex Tester

Test and debug Regular Expressions in real-time

//gi
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._%+-]
Any character in a-zA-Z0-9._%+-
+
1 or more (greedy)
@
Literal "@"
[a-zA-Z0-9.-]
Any character in a-zA-Z0-9.-
+
1 or more (greedy)
\.
Literal "."
[a-zA-Z]
Any character in a-zA-Z
{2,}
2 or more times
4 matches

Regex Guide — Learn by Example

Regular Expressions (Regex) are patterns used to match text. Click "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).

About This Tool

A free online regex tester that lets you write, test, and debug regular expressions in real-time. Supports JavaScript regex syntax with all standard flags including global, case-insensitive, multiline, dotall, and unicode modes.

Features include live match highlighting, real-time pattern explanation, find-and-replace with substitution tokens, capture group inspection, common pattern presets, interactive tutorial, and a built-in cheatsheet. All processing happens locally in your browser — no data is sent to any server.

Notes

  • Real-Time Matching — As you type your regex pattern and test string, matches are highlighted instantly with color-coded groups and match indices.
  • Pattern Explanation — Built-in regex explanation engine breaks down your pattern token-by-token, showing what each character class, quantifier, and group does.
  • Replace Mode — Switch to replace mode to test regex-based string replacements with support for backreferences ($1, $2, etc.) and named groups.
  • Preset Patterns — 8 common patterns including email, URL, phone number, IPv4, HTML tags, dates, hex colors, and password validation.
  • Interactive Tutorial — Learn regex from scratch with 9 sections covering literal characters, character classes, quantifiers, anchors, groups, lookahead/lookbehind, and more — each with "Try it" examples.
  • ReDoS Protection — Built-in time guard aborts regex execution after 200ms to prevent catastrophic backtracking from freezing your browser.
  • All processing happens entirely in your browser. No data is sent to any server.

Online Regex Tester — Test Regular Expressions in Real-Time

Our free online regex tester lets you write, test, and debug regular expressions with instant visual feedback. Paste your pattern and test string, and see matches highlighted in real-time. Supports all JavaScript regex flags including global (g), case-insensitive (i), multiline (m), dotAll (s), unicode (u), and sticky (y). Perfect for developers, QA engineers, and anyone working with text pattern matching.

Why Use an Online Regex Tester?

  • Instant Feedback — See matches highlighted as you type, eliminating the compile-test-debug cycle.
  • Visual Debugging — Color-coded match groups make it easy to understand which parts of your pattern capture which text.
  • Learn by Doing — The built-in explanation engine and interactive tutorial help you understand regex syntax without memorizing documentation.
  • Safe Testing — ReDoS protection ensures catastrophic backtracking patterns won't freeze your browser.
  • No Installation — Works directly in the browser. No IDE plugins, npm packages, or setup required.

Common Regex Use Cases

  • Email Validation — Match email addresses with patterns like [a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,}
  • URL Extraction — Find and extract URLs from text using protocol-aware patterns.
  • Data Cleaning — Remove unwanted characters, normalize whitespace, or extract structured data from unstructured text.
  • Log Parsing — Parse server logs, error messages, and structured text with capture groups.
  • Form Validation — Validate phone numbers, postal codes, credit card numbers, and other structured input.

Privacy & Security

All regex processing runs entirely in your browser using JavaScript's native RegExp engine. Your patterns, test strings, and results are never sent to any server. The tool includes input size limits and execution time guards to prevent browser freezes from complex patterns.

Nattang

Your trusted source for premium digital products. Instant download, lifetime access.

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

All transactions are encrypted and secure.

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