Regex Tester
Common Patterns
Examples
Cheat Sheet
Guide

🔍 Regular Expression Tester

g (global)
i (ignore case)
m (multiline)
s (dotall)
u (unicode)
y (sticky)

Test Results

0 matches
Enter a regex pattern and test string to see matches...

📋 Common Regex Patterns

📧 Email Validation

^[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,}$
Validates most common email address formats

🔒 Strong Password

^(?=.*[a-z])(?=.*[A-Z])(?=.*\d)(?=.*[@$!%*?&])[A-Za-z\d@$!%*?&]{8,}$
At least 8 chars, 1 uppercase, 1 lowercase, 1 digit, 1 special char

📱 Phone Number

^\+?[1-9]\d{1,14}$
International phone number format (E.164)

🌐 URL Validation

^(https?|ftp)://[^\s/$.?#].[^\s]*$
Validates HTTP, HTTPS, and FTP URLs

📅 Date (YYYY-MM-DD)

^\d{4}-(0[1-9]|1[0-2])-(0[1-9]|[12][0-9]|3[01])$
ISO 8601 date format validation

🕐 Time (24-hour)

^([01]?[0-9]|2[0-3]):[0-5][0-9]$
24-hour time format (HH:MM)

💰 Currency Amount

^\$?\d{1,3}(,\d{3})*(\.\d{2})?$
Currency format with optional $ and commas

🌐 IP Address

^(?:[0-9]{1,3}\.){3}[0-9]{1,3}$
IPv4 address validation

🆔 UUID/GUID

^[A-Za-z0-9]{8}-[A-Za-z0-9]{4}-[A-Za-z0-9]{4}-[A-Za-z0-9]{4}-[A-Za-z0-9]{12}$
Universally Unique Identifier format

🎨 Hex Color

^#([A-Fa-f0-9]{6}|[A-Fa-f0-9]{3})$
Hexadecimal color codes (#RGB or #RRGGBB)

👤 Username

^[a-zA-Z0-9_-]+$
Alphanumeric username with underscores and hyphens

📮 ZIP Code (US)

^\d{5}(-\d{4})?$
US ZIP code format (5 digits or 5+4)

📋 Practical Examples

📧 Email Extraction

Pattern: \b[A-Za-z0-9._%+-]+@[A-Za-z0-9.-]+\.[A-Z|a-z]{2,}\b

Use Case: Extract all email addresses from text content, useful for contact information mining.

Sample Text: "Contact us at support@company.com or sales@business.org"

📱 Phone Number Cleanup

Pattern: (\+?\d{1,3}[-.\s]?)?\(?\d{3}\)?[-.\s]?\d{3}[-.\s]?\d{4}

Use Case: Find and standardize phone numbers in various formats.

Sample Text: "Call (555) 123-4567 or +1-555.987.6543"

🔗 URL Extraction

Pattern: https?://(?:[-\w.])+(?:\:[0-9]+)?(?:/(?:[\w/_.])*(?:\?(?:[\w&=%.])*)?(?:\#(?:[\w.])*)?)?

Use Case: Extract all URLs from web content or documents.

Sample Text: "Visit https://example.com or http://subdomain.site.org/path"

💳 Credit Card Validation

Pattern: \b(?:\d{4}[-\s]?){3}\d{4}\b

Use Case: Identify credit card numbers in text (for security scanning).

Sample Text: "Card: 1234-5678-9012-3456 or 1234567890123456"

📅 Date Format Conversion

Pattern: (\d{1,2})/(\d{1,2})/(\d{4})

Use Case: Convert date formats from MM/DD/YYYY to other formats.

Sample Text: "Events: 12/25/2024, 01/01/2025, 07/04/2024"

🏷️ HTML Tag Removal

Pattern: <[^>]*>

Use Case: Strip HTML tags from content to get plain text.

Sample Text: "<p>Hello <strong>world</strong>!</p>"

💰 Price Extraction

Pattern: \$\d+(?:\.\d{2})?

Use Case: Extract price information from product descriptions.

Sample Text: "Product costs $29.99, sale price $19.99, shipping $5.00"

🔢 Number Validation

Pattern: ^-?\d+(\.\d+)?$

Use Case: Validate numeric input including decimals and negative numbers.

Sample Text: "Values: 123, -45.67, 0.123, -999"

📖 Regex Cheat Sheet

Character Classes

  • . - Any character except newline
  • \d - Any digit (0-9)
  • \D - Any non-digit
  • \w - Any word character (a-z, A-Z, 0-9, _)
  • \W - Any non-word character
  • \s - Any whitespace character
  • \S - Any non-whitespace character
  • [abc] - Any character in the set
  • [^abc] - Any character not in the set
  • [a-z] - Any character in the range

Quantifiers

  • * - 0 or more occurrences
  • + - 1 or more occurrences
  • ? - 0 or 1 occurrence
  • {n} - Exactly n occurrences
  • {n,} - n or more occurrences
  • {n,m} - Between n and m occurrences
  • *? - Non-greedy 0 or more
  • +? - Non-greedy 1 or more
  • ?? - Non-greedy 0 or 1

Anchors

  • ^ - Start of string/line
  • $ - End of string/line
  • \b - Word boundary
  • \B - Non-word boundary
  • \A - Start of string
  • \Z - End of string

Groups and Lookarounds

  • (abc) - Capturing group
  • (?:abc) - Non-capturing group
  • (?=abc) - Positive lookahead
  • (?!abc) - Negative lookahead
  • (?<=abc) - Positive lookbehind
  • (? - Negative lookbehind
  • \1 - Back reference to group 1

Special Characters

  • | - Alternation (OR)
  • \ - Escape special character
  • \n - Newline
  • \r - Carriage return
  • \t - Tab
  • \0 - Null character
  • \f - Form feed
  • \v - Vertical tab

Flags

  • g - Global: Find all matches
  • i - Ignore case: Case-insensitive matching
  • m - Multiline: ^ and $ match line breaks
  • s - Dotall: . matches newlines
  • u - Unicode: Full unicode support
  • y - Sticky: Match from lastIndex

📚 Regex Guide

What are Regular Expressions?

Regular expressions (regex) are powerful patterns used to match character combinations in strings. They're essential tools for text processing, validation, and data extraction in programming and data analysis.

Basic Syntax

A regex pattern consists of literal characters and special metacharacters that define the search criteria:

/pattern/flags
          

Example: /hello/i matches "hello", "Hello", "HELLO" (case-insensitive)

Building Your First Regex

Step 1: Start with literal characters

cat

This matches the exact string "cat"

Step 2: Add character classes

[Cc]at

This matches "cat" or "Cat"

Step 3: Use quantifiers

[Cc]ats?

This matches "cat", "Cat", "cats", or "Cats"

Common Use Cases

  • Form Validation: Email, phone, password validation
  • Text Processing: Find and replace operations
  • Data Extraction: Parse logs, extract information
  • Input Sanitization: Clean user input
  • URL Routing: Match URL patterns in web applications

Best Practices

  • Start Simple: Begin with basic patterns and add complexity gradually
  • Test Thoroughly: Use tools like this tester to validate patterns
  • Be Specific: Avoid overly broad patterns that match unintended text
  • Use Non-Capturing Groups: When you don't need to extract the matched text
  • Escape Special Characters: Use backslashes for literal special characters
  • Consider Performance: Complex patterns can be slow on large texts

Common Mistakes

  • Catastrophic Backtracking: Avoid nested quantifiers like (a+)+
  • Greedy vs Non-Greedy: Understand when to use *? vs *
  • Case Sensitivity: Remember to use the 'i' flag when needed
  • Escaping Issues: Don't forget to escape special characters in strings
  • Multiline Confusion: Use 'm' flag for proper ^ and $ behavior

Debugging Tips

  • Break complex patterns into smaller parts
  • Use online regex testers to visualize matches
  • Test with various input examples
  • Use capturing groups to understand what's being matched
  • Check flag settings (global, case-insensitive, etc.)

Learning Resources

  • Practice with real-world examples
  • Use regex visualization tools
  • Study common patterns and modify them
  • Join regex communities and forums
  • Read documentation for your programming language's regex implementation