Regular expressions (regex) are powerful pattern-matching tools used in programming, text editing, and data validation.
Basic Syntax
| Pattern | Matches |
|---|---|
. | Any single character |
\d | Any digit (0-9) |
\w | Any word character |
\s | Any whitespace |
* | Zero or more |
+ | One or more |
? | Zero or one |
^ | Start of string |
$ | End of string |
Common Patterns
Email Validation
^[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,}$
URL Matching
https?:\/\/[\w.-]+\.[a-zA-Z]{2,}[\/\w.-]*
Phone Number
\+?\d{1,3}[\s-]?\(?\d{1,4}\)?[\s-]?\d{3,4}[\s-]?\d{4}
Tips for Writing Regex
() for capturing, (?:) for non-capturing\d{4} is better than \d+ when you know the lengthTry It Yourself
Test your regex patterns with real-time matching using our Regex Tester.