Regex Tester with Explanation

Test and validate your regular expressions with real-time matching, detailed explanations, and pattern analysis. Perfect for learning and debugging regex patterns.

Regex Tester

Invalid
//gi
Cannot access 'E' before initialization
Contact us at support@example.com or sales@test.org Visit our website: https://www.example.com Phone: (555) 123-4567 or +1-555-987-6543 Email: john.doe@company.co.uk for more information.

Master regular expressions with real-time testing!

Test patterns, see matches, and learn regex with detailed explanations

What are Regular Expressions?

Regular expressions (regex) are powerful patterns used to match and manipulate text. They provide a concise and flexible way to search, extract, and replace text patterns in strings.

Common Use Cases

  • Email validation
  • Phone number formatting
  • URL extraction
  • Data cleaning and parsing
  • Input validation in forms
  • Log file analysis

Benefits

  • Powerful pattern matching
  • Concise syntax
  • Cross-language support
  • Fast text processing
  • Flexible and expressive
  • Industry standard

Regex Basics and Syntax

Basic Characters

Most characters match themselves literally.

hello matches the word "hello"
123 matches the digits "123"

Special Characters (Metacharacters)

Characters with special meaning in regex.

. - Matches any character
* - Matches 0 or more
+ - Matches 1 or more
? - Matches 0 or 1
^ - Start of string
$ - End of string
[] - Character class
() - Grouping
| - Alternation (OR)
\ - Escape character
{} - Quantifiers
\b - Word boundary

Character Classes

Predefined sets of characters.

\d - Any digit (0-9)
\w - Word character (a-zA-Z0-9_)
\s - Whitespace character
[a-z] - Lowercase letters
[A-Z] - Uppercase letters
\D - Not a digit
\W - Not a word character
\S - Not whitespace
[0-9] - Any digit
[^a-z] - Not lowercase

Quantifiers

Specify how many times a pattern should match.

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

Common Regex Patterns

Email Validation

/^[^\s@]+@[^\s@]+\.[^\s@]+$/

Matches basic email format: one or more non-whitespace/non-@ characters, followed by @, domain, dot, and extension.

Phone Number (US Format)

/^\(?([0-9]{3})\)?[-. ]?([0-9]{3})[-. ]?([0-9]{4})$/

Matches US phone numbers in formats like (123) 456-7890, 123-456-7890, or 123.456.7890.

URL Validation

/^https?:\/\/(www\.)?[-a-zA-Z0-9@:%._\+~#=]{1,256}\.[a-zA-Z0-9()]{1,6}\b([-a-zA-Z0-9()@:%_\+.~#?&//=]*)$/

Matches HTTP and HTTPS URLs with optional www, domain, and path components.

Date Format (MM/DD/YYYY)

/^(0[1-9]|1[0-2])\/(0[1-9]|[12][0-9]|3[01])\/([0-9]{4})$/

Matches dates in MM/DD/YYYY format with basic validation for months (01-12) and days (01-31).

Password Strength

/^(?=.*[a-z])(?=.*[A-Z])(?=.*\d)(?=.*[@$!%*?&])[A-Za-z\d@$!%*?&]{8,}$/

Requires at least 8 characters with lowercase, uppercase, digit, and special character.

IP Address (IPv4)

/^(?:(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.){3}(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)$/

Matches valid IPv4 addresses (0.0.0.0 to 255.255.255.255).

Regex Flags and Modifiers

Common Flags

g
Global
Find all matches, not just the first one
i
Case Insensitive
Ignore case when matching
m
Multiline
^ and $ match line breaks
s
Dotall
. matches newline characters

Examples

/hello/g
Find all instances of "hello"
/HELLO/i
Match "hello", "Hello", "HELLO"
/^start/m
Match "start" at beginning of lines
/hello/gi
Global and case-insensitive

Regex Best Practices

✅ Good Practices

  • Start with simple patterns and build complexity gradually
  • Use raw strings in programming languages to avoid escaping
  • Comment complex regex patterns
  • Test with edge cases and boundary conditions
  • Use non-capturing groups when you don't need the match
  • Be specific rather than overly permissive
  • Consider performance for large text processing

❌ Common Pitfalls

  • Overusing .* (greedy matching)
  • Not escaping special characters
  • Writing overly complex patterns
  • Ignoring catastrophic backtracking
  • Not considering Unicode characters
  • Using regex for non-text data parsing
  • Not testing with real-world data