Regex Tester
Test regular expressions against text with real-time match highlighting.
Type a regex pattern, paste some test text and see matches highlighted as you type. This tool uses JavaScript regex syntax and shows you capture groups, match positions and match count in real time. No more guessing whether your pattern works.
What You Can Do Here
- See matches highlighted in real time as you type your pattern
- View capture groups and their values for each match
- Toggle all JavaScript flags (g, i, m, s, u, y)
- Get match count and position info for every result
- Access a quick-reference cheatsheet for common patterns
Regex Cheatsheet
- . - Matches any character except newline
- \d - Any digit (0-9). \D matches non-digits.
- \w - Any word character (letters, digits, underscore). \W matches non-word characters.
- \s - Any whitespace (space, tab, newline). \S matches non-whitespace.
- * - Zero or more of the previous token
- + - One or more of the previous token
- ? - Zero or one (makes something optional)
- {n,m} - Between n and m occurrences
- [abc] - Any one character from the set
- [^abc] - Any character NOT in the set
- (group) - Capture group. Use (?:group) for non-capturing.
- ^ - Start of string. $ - End of string.
- | - OR operator. "cat|dog" matches either word.
Common Regex Patterns
Here are patterns developers reach for all the time:
- Email (basic) - [a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,}
- Phone (US) - \(?\d{3}\)?[-.\s]?\d{3}[-.\s]?\d{4}
- URL - https?:\/\/[\w\-]+(\.[\w\-]+)+[/#?]?.*$
- IP Address - \b\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}\b
Why Your Regex Might Work in One Language but Not Another
Regex has different "flavors." JavaScript, Python (re module), PCRE (PHP, Perl) and .NET all have slightly different syntax and feature sets. Lookbehind support, named groups and Unicode handling all vary. This tool uses JavaScript's regex engine, which is what you'd use in Node.js and browser-based code. If you're writing Python or PHP regex, double-check flavor-specific differences.
How to Use
- Type your regex pattern in the pattern field.
- Set flags - g for global (all matches), i for case-insensitive, m for multiline.
- Paste your test text in the text area below.
- Matches get highlighted instantly. Check capture groups in the results panel.
Frequently Asked Questions
How do I use the Regex Tester?
Enter a pattern and test text. The tool highlights matches and shows what the pattern captures. Start with a small sample before testing a full file.
Why does my regex not match anything?
Check escaping, flags and whether the pattern expects line starts, word boundaries or exact casing. Also confirm that the test text really contains the character you are trying to match.
What do regex flags like `g`, `i` and `m` mean?
`g` finds all matches, `i` ignores case and `m` changes how line anchors work. Use only the flags you need. Extra flags can make a pattern behave differently than expected.
Why does my regex work in one language but not another?
Regex engines differ. JavaScript, Python, PHP and PCRE support different features. Lookbehind, Unicode handling and named groups are common places where patterns break. Check the target language before copying a pattern into production.
Can regex parse HTML?
It can match simple fragments, but it is not a full HTML parser. Use a parser for nested, messy or user-generated HTML. Regex is safer for small checks than full document parsing.