RegEx Tester

Test and debug regular expressions with our interactive RegEx tester. Real-time matching, syntax highlighting, and visual feedback.

Regular Expression

Test Text

Here are some examples to test: Email: [email protected] Phone: (123) 456-7890 Date: 2024-03-15 URL: https://example.com Color: #FF5733 IP: 192.168.1.1 Card: 4111111111111111

Matches

0

Understanding Capture Groups

Capture groups are parts of your regex pattern inside parentheses that let you extract specific matches. For example, with the email pattern:

Pattern: ([\w.-]+)@([\w.-]+\.\w{2,})Text: [email protected] Match: [email protected] Group 1: john.doe (username) Group 2: example.com (domain)

Each set of parentheses ( ) creates a numbered group, which you can use to extract parts of the match.


Regular Expressions Guide

A comprehensive guide to understanding and using regular expressions

Basic Metacharacters

Metacharacters are the building blocks of regular expressions that have special meaning. They allow you to define patterns beyond literal text matching, enabling powerful search and validation capabilities.

Dot (.)

Matches any single character except newline. Useful for matching patterns where any character is acceptable.

Using c.t finds three-letter patterns starting with 'c' and ending with 't':
✓ "cat" in "black cat"
✓ "cut" in "shortcut"
✗ "ct" (no middle char), "cart" (too long)

Quantifiers (*, +, ?)

Control how many times a pattern can match.

*Zero or more occurrences
Using ab*c matches 'ac' or 'abc' with any number of 'b's:
✓ "ac" in "ac"
✓ "abbbbc" in "abbbbc"
✗ "ab" (no 'c'), "bac" (wrong order)
+One or more occurrences
Using ab+c requires at least one 'b':
✓ "abc" in "abc"
✓ "abbc" in "abbc"
✗ "ac" (no 'b'), "a" (incomplete)
?Zero or one occurrence (optional)
Using colou?r matches both spellings:
✓ "color" in "color"
✓ "colour" in "colour"
✗ "colouur" (too many u's)

Exact Quantifiers

When you need precise control over the number of occurrences, exact quantifiers let you specify exact counts or ranges. These are particularly useful for matching structured data like phone numbers, dates, or any pattern with a known length.

Fixed Count {n}

Match exactly n occurrences of a pattern.

Using \\d3 matches exactly three digits:
✓ "123" in "ID: 123"
✓ "456" in "456 items"
✗ "12" (too few), "1234" (too many)

Range {n,m}

Match between n and m occurrences.

Using \d{2,4} matches 2 to 4 digits:
✓ "12" in "ID: 12"
✓ "1234" in "PIN: 1234"
✗ "1" (too few), "12345" (too many)

Minimum Count {n,}

Match at least n occurrences.

Using \d{2,} matches 2 or more digits:
✓ "12" in "ID: 12"
✓ "12345" in "ZIP: 12345"
✗ "1" (too few digits)

Groups and Assertions

Groups allow you to treat multiple characters as a single unit and capture parts of the match. Assertions let you add conditions to your matches without including them in the result.

Capturing Groups ()

Group patterns together and capture the matched text.

Using (\\w+)@(\\w+\\.com) captures username and domain:
✓ "[email protected]" with groups:
Group 1: "john" (username)
Group 2: "example.com" (domain)
✗ "invalid@email" (incomplete domain)

Lookahead (?=) and Lookbehind (?<=)

Match patterns only if followed or preceded by another pattern.

Using \\w+(?=@) matches username if followed by @:
✓ "john" in "[email protected]"
✓ "user" in "[email protected]"
✗ "john" in "john.doe" (no @ after)

Common Patterns

These are frequently used regex patterns for common validation tasks like emails, phone numbers, and dates. These patterns have been tested and optimized for real-world use cases.

Email Validation

Basic email format validation that covers most common email patterns.

Using [a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+.[a-zA-Z]{2,}:
✗ "invalid@email" (no TLD)
✗ "@domain.com" (no username)

Phone Numbers

Matches common US phone number formats with optional country code.

Using (\+1[-\s]?)?\(?([0-9]3)\)?[-\s]?([0-9]3)[-\s]?([0-9]4):
✓ "(123) 456-7890"
✓ "+1-123-456-7890"
✓ "1234567890"
✗ "123-456" (incomplete)
✗ "abc-def-ghij" (not numbers)

Date Formats

Matches common date formats including MM/DD/YYYY and YYYY-MM-DD.

Using (0[1-9]|1[0-2])[-/](0[1-9]|[12][0-9]|3[01])[-/](19|20)\d\d:
✓ "12/25/2023"
✓ "01-31-2024"
✗ "13/01/2023" (invalid month)
✗ "2023/12/25" (wrong format)

URL Validation

Matches valid URLs with optional protocol and subdomains.

Using https?://(www.)?[-a-zA-Z0-9@:%._+~#=]{1,256}.[a-zA-Z0-9()]{1,6}:
✓ "https://www.example.com"
✓ "http://sub.domain.co.uk/path"
✗ "just.words"
✗ "https://" (incomplete)

Password Strength

Validates password with minimum requirements: 8+ chars, uppercase, lowercase, number, special char.

Using ^(?=.*[a-z])(?=.*[A-Z])(?=.*d)(?=.*[@$!%*?&])[A-Za-zd@$!%*?&]{8,}$:
✓ "Pass123$word"
✓ "Str0ng!Pass"
✗ "weak" (too short)
✗ "Password123" (no special char)

Our RegEx tester helps you build and test regular expressions in real-time. See matches instantly, test against your own text, and use common patterns to get started quickly. All processing happens in your browser for maximum privacy and speed.

Frequently Asked Questions

What is a Regular Expression (RegEx)?
A regular expression is a sequence of characters that defines a search pattern. It's commonly used for string matching, validation, and text manipulation.
How do RegEx flags work?
Flags modify how the regex pattern matches. Common flags include 'g' (global), 'i' (case-insensitive), 'm' (multiline), and 's' (dot matches newlines).
What are capture groups?
Capture groups are parts of a regex pattern enclosed in parentheses that let you extract specific portions of the matched text. They're useful for complex pattern matching and text extraction.
How do I use lookahead and lookbehind?
Lookahead (?=) and lookbehind (?<=) are zero-width assertions that match a pattern without including it in the result. They're useful for pattern matching with specific conditions.
Is this tool secure?
Yes, all pattern matching happens directly in your browser. No data is sent to any server or stored anywhere.