Regex Tester

Test and debug regular expressions in real-time. See matches highlighted and perform search-and-replace operations.

Pattern
Enter your regular expression
//gim
Test String
Enter text to test against the pattern
Results
0 matches found
Contact us at [email protected] for help. You can also reach out to [email protected] or [email protected]. Invalid emails like test@incomplete or @nouser.com won't match.

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,}$