Write a regular expression and see instantly which parts of your sample text it matches, with the matches highlighted directly in the text and a running count. Regular expressions are easy to get subtly wrong, so testing against real text before dropping a pattern into code saves a lot of trial and error.
How to use it
- Type your pattern into the pattern field, without the surrounding slashes.
- Set any flags you need, like g for global matching or i for case insensitive.
- Paste the text you want to test against.
- Watch matches get highlighted as you adjust the pattern.
- Check the match count to confirm it's finding what you expect.
- Keep refining until it matches exactly what you intend, no more and no less.
When it helps
- Building and testing a pattern to validate an email address or a phone number before using it in a form.
- Figuring out why a regular expression already in your code isn't matching what you expect.
- Pulling every instance of a pattern, like URLs or hashtags, out of a bigger block of text.
- Learning regex syntax by experimenting against real examples.
- Making sure a pattern doesn't accidentally match more than intended before it ships.
Good to know
- Test with examples that should match and examples that shouldn't, to catch a pattern that's too broad.
- Use the g flag whenever you want every match, not just the first one.
- Escape special characters like a period or a question mark with a backslash when you mean them literally.
- Break a complex pattern into smaller pieces and test each part separately before combining them. Isolating the failing part is much faster than debugging one long pattern at once.
- When you finally get a pattern working, add a short comment nearby in your actual code explaining what it matches, since regex is notoriously hard to read again months later.
Questions
What does the g flag do?
It tells the engine to find every match rather than stopping at the first one, which matters if you're counting or highlighting all occurrences.
Why isn't my pattern matching anything?
Common causes are forgetting to escape a special character, a case sensitivity issue the i flag would fix, or a logical mistake in the pattern. Try simplifying it to find the issue.
Can I test a pattern with capture groups?
Yes, parentheses in your pattern create groups and matches still highlight correctly. The count reflects full matches, not individual groups.
Why does my pattern match more than I expect?
This is often a greedy quantifier like .* matching as much as possible. Adding a question mark after it, like .*?, makes it lazy and matches as little as possible instead.
Can I test multiline text with the m flag?
Yes, add m to the flags alongside anything else you need, and anchors like the start and end markers will then match the start and end of each line rather than only the whole string.
Does this support named capture groups?
Yes, since it uses your browser's standard regex engine, named groups written with the usual syntax work the same way they would in your own JavaScript code.