Common Regex Examples

\d{3}-\d{3}-\d{4}
Phone number (555-123-4567)
[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,}
Email address
https?://[^\s]+
URL (http/https)
#[0-9A-Fa-f]{6}
Hex color code
\b\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}\b
IP address

Last updated

Regex Tester

Test regular expressions online with real-time matching and highlighting. Our regex tester helps you validate patterns, debug regex, and learn regular expression syntax.

Regex Flags

Common Regex Patterns

Digits: \d or [0-9]

Letters: [a-zA-Z]

Whitespace: \s

Word characters: \w (letters, digits, underscore)

Any character: .

Start of string: ^

End of string: $

Common Regex Patterns Reference

  • IPv4 address: \b(?:\d{1,3}\.){3}\d{1,3}\b
  • Hex color code: #([A-Fa-f0-9]{6}|[A-Fa-f0-9]{3})
  • Credit card (basic): \b\d{4}[\s\-]?\d{4}[\s\-]?\d{4}[\s\-]?\d{4}\b
  • Slug (URL-friendly): ^[a-z0-9]+(?:-[a-z0-9]+)*$
  • Semantic version: ^\d+\.\d+\.\d+(?:-[a-zA-Z0-9.]+)?$
  • ISO date: ^\d{4}-(?:0[1-9]|1[0-2])-(?:0[1-9]|[12]\d|3[01])$

All regex testing happens entirely in your browser. The tool supports JavaScript, Python, PHP, Java, and .NET regex flavors with real-time match highlighting and captured group display.

Quantifiers

  • * - 0 or more times
  • + - 1 or more times
  • ? - 0 or 1 time (optional)
  • {n} - Exactly n times
  • {n,} - n or more times
  • {n,m} - Between n and m times

Common Use Cases

  • Validating email addresses and phone numbers
  • Extracting URLs from text
  • Finding patterns in log files
  • Data validation in forms
  • Text search and replace
  • Parsing structured data

Examples

Example 1: Email Validation

Pattern: ^[a-zA-Z0-9._%+\-]+@[a-zA-Z0-9.\-]+\.[a-zA-Z]{2,}$
Flags: i (case-insensitive)

Test strings:
  user@example.com          ✅ Match
  user.name+tag@example.org ✅ Match
  user@subdomain.example.com ✅ Match
  invalid-email             ❌ No match
  @example.com              ❌ No match
  user@                     ❌ No match
  user@.com                 ❌ No match

Example 2: URL Extraction

Pattern: https?:\/\/[^\s"'<>]+
Flags: g (global — find all matches)

Test text:
  "Visit https://example.com for more info.
   Also check http://docs.example.com/guide and
   our blog at https://blog.example.com/post/123"

Matches:
  1. https://example.com
  2. http://docs.example.com/guide
  3. https://blog.example.com/post/123

Example 3: Phone Number Validation

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

Test strings:
  (555) 123-4567    ✅ Match
  555-123-4567      ✅ Match
  555.123.4567      ✅ Match
  +1 555 123 4567   ✅ Match
  5551234567        ✅ Match
  123-456           ❌ No match (too short)
  (555) 123-45678   ❌ No match (too long)

Frequently Asked Questions

Enter your regex pattern in the pattern field and your test text in the text area. The tool will highlight matches in real-time and show match details. You can toggle flags like case-insensitive (i), global (g), and multiline (m).

Regex flags modify pattern matching behavior: 'g' (global) finds all matches, 'i' (case-insensitive) ignores case, 'm' (multiline) treats ^ and $ as line boundaries, 's' (dotall) makes . match newlines, 'u' (unicode) enables unicode support.

Use pattern: [a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,} - This matches most email formats. For more strict validation, use: ^[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,}$

The 'g' (global) flag makes regex find all matches in the text instead of stopping after the first match. Without 'g', only the first match is returned. With 'g', all occurrences are found.