Regex Tester
Test and debug regular expressions in real-time. See matches highlighted and perform search-and-replace operations.
What is Regular Expression (Regex)?
A Regular Expression (Regex) is a sequence of characters that defines a search pattern. It's used for pattern matching within strings, making it powerful for validation, search, and text manipulation.
Common Regex Syntax
Character Classes
| Pattern | Matches |
|---------|---------|
| . | Any character except newline |
| \d | Any digit (0-9) |
| \D | Any non-digit |
| \w | Word character (a-z, A-Z, 0-9, _) |
| \W | Non-word character |
| \s | Whitespace character |
| \S | Non-whitespace character |
Quantifiers
| Pattern | Meaning |
|---------|---------|
| * | 0 or more |
| + | 1 or more |
| ? | 0 or 1 (optional) |
| {n} | Exactly n times |
| {n,} | n or more times |
| {n,m} | Between n and m times |
Anchors
| Pattern | Matches |
|---------|---------|
| ^ | Start of string/line |
| $ | End of string/line |
| \b | Word boundary |
| \B | Non-word boundary |
Groups and References
| Pattern | Description |
|---------|-------------|
| (abc) | Capturing group |
| (?:abc) | Non-capturing group |
| (?=abc) | Positive lookahead |
| (?!abc) | Negative lookahead |
| \1 | Backreference to group 1 |
Regex Flags
| Flag | Description |
|------|-------------|
| g | Global - find all matches |
| i | Case-insensitive |
| m | Multiline - ^ and $ match line boundaries |
| s | Dotall - . matches newlines |
| u | Unicode support |
| y | Sticky - matches at exact position |
Common Use Cases
- Email validation:
^[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,}$ - Phone number:
^\(?\d{3}\)?[-.\s]?\d{3}[-.\s]?\d{4}$ - URL:
https?:\/\/[\w\-]+(\.[\w\-]+)+[\w\-.,@?^=%&:/~+#]* - Strong password:
^(?=.*[a-z])(?=.*[A-Z])(?=.*\d)(?=.*[@$!%*?&])[A-Za-z\d@$!%*?&]{8,}$