How to Use the Regex Tester
Regular expressions (regex) are powerful patterns used for matching, searching, and manipulating text. This tool provides real-time testing with visual highlighting to help you build and debug your patterns.
- Enter Pattern: Type your regex pattern in the input field between the slashes.
- Set Flags: Enable Global (g) to find all matches, Case Insensitive (i) to ignore case, or Multiline (m) for line-by-line matching.
- Add Test String: Enter the text you want to test against your pattern.
- View Results: Matches are highlighted in yellow, and capture groups are displayed below.
Common Regex Patterns Explained
Email Validation
^[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,}$Matches standard email formats with alphanumeric characters, dots, and common special characters before the @.
URL Matching
https?:\/\/[^\s]+Matches HTTP and HTTPS URLs, capturing everything until whitespace.
Phone Number
\d{3}-\d{3}-\d{4}Matches US phone numbers in the format 123-456-7890.
Date Format
\d{4}-\d{2}-\d{2}Matches dates in ISO format (YYYY-MM-DD).
Regex Syntax Quick Reference
| Symbol | Meaning | Example |
|---|---|---|
| . | Any character except newline | a.c matches "abc" |
| * | Zero or more of previous | ab*c matches "ac", "abc", "abbc" |
| + | One or more of previous | ab+c matches "abc", "abbc" |
| ? | Zero or one of previous | colou?r matches "color", "colour" |
| ^ | Start of string/line | ^Hello matches "Hello world" |
| $ | End of string/line | world$ matches "Hello world" |
| \d | Any digit (0-9) | \d+ matches "123" |
| \w | Word character (a-z, A-Z, 0-9, _) | \w+ matches "hello_123" |
| [abc] | Character class | [aeiou] matches vowels |
| (abc) | Capture group | (ab)+ matches "abab" |
Frequently Asked Questions
What are regex flags?
Flags modify how the regex engine interprets your pattern. The global flag (g) finds all matches instead of just the first one. Case insensitive (i) ignores letter case. Multiline (m) makes ^ and $ match line starts/ends, not just string starts/ends.
What are capture groups?
Capture groups, created with parentheses (), extract specific parts of a match. For example, the pattern (\d+)-(\d+) on "123-456" would capture "123" in group 1 and "456" in group 2. This is useful for extracting data from structured text.
Why is my pattern not matching?
Common issues include: forgetting to escape special characters (use \. for a literal dot), missing the global flag when expecting multiple matches, or case sensitivity (try enabling the i flag). Also check for invisible characters like extra spaces.
Are regex patterns the same in all programming languages?
While core syntax is similar, there are variations. JavaScript regex (used in this tool) differs slightly from Python, Java, or PCRE. Features like lookbehinds, named groups, and Unicode support vary between implementations. Always test in your target environment.