Regex Examples: Common Patterns for Real Use Cases
Regular expressions (regex) are used to search, match, and validate text using pattern rules. Developers use regex for form validation, data extraction, log analysis, and text processing.
Below are practical regex examples you can copy and use immediately in real-world scenarios.
Email validation
^[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-z]{2,}$
Matches most valid email formats used in forms and user input validation.
Strong password
^(?=.*[a-z])(?=.*[A-Z])(?=.*\d)(?=.*[^A-Za-z0-9]).{8,}$
Ensures a password contains uppercase, lowercase, numbers, and special characters.
URL matching
^(https?:\/\/)?([\w-]+\.)+[\w-]+(\/[^\s]*)?$
Matches most website URLs, including optional protocols and paths.
Phone number
^\+?[0-9][0-9\s().-]{7,}$
Basic international phone number validation.
IP address
^(?:(?:25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)\.){3}(?:25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)$
Matches valid IPv4 addresses.
Date format (YYYY-MM-DD)
^\d{4}-(0[1-9]|1[0-2])-(0[1-9]|[12]\d|3[01])$
Validates ISO date format.
Numbers only
^\d+$
Allows only digits.
Letters only
^[A-Za-z]+$
Matches alphabetic characters only.
Whitespace removal
\s+
Matches one or more whitespace characters.
Find words
\b\w+\b
Extracts individual words from text.
Test regex patterns instantly
You can test and debug all these regex patterns using our interactive tool:
The tool highlights matches in real time and supports JavaScript regex flags.
Common regex mistakes
- Missing escape characters
- Wrong anchors (^ and $)
- Incorrect quantifiers
- Forgetting regex flags
Where regex is used
- Form validation
- Search and replace
- Data extraction
- Log parsing
- Web scraping
- API data validation