regex 2025-01-14
Regular Expressions Basics for Beginners
Learn the fundamentals of regular expressions with practical examples.
Regular expressions (regex) are powerful patterns for matching text.
Basic Patterns
|---------|---------|
Quantifiers
|------------|---------|
Character Classes
[abc] # a, b, or c
[^abc] # Not a, b, or c
[a-z] # a through z
[A-Za-z] # Any letter
Common Patterns
Email validation:
^[\w.-]+@[\w.-]+\.[a-zA-Z]{2,}$
Phone number:
^\d{3}-\d{3,4}-\d{4}$
URL:
^https?://[\w.-]+(/[\w./-]*)?$
Groups and Capturing
(abc) # Capturing group
(?:abc) # Non-capturing group
\1 # Backreference to group 1
Flags
- g: Global (find all matches)
- i: Case insensitive
- m: Multiline mode
Use our Regex Tester to practice and validate your patterns.