A regular expression is a pattern for finding text: every email address in a file, every date in a log, every line that starts with a number. Regex is powerful and easy to get subtly wrong, so test a pattern on real examples before trusting it. The Regex Tester does that in your browser.
How to test a regex, step by step
- Paste your sample text into the “Input” box. Include examples that should match and examples that should not.
- Type your pattern in “Regular expression”, without the surrounding slashes.
- Set the flags in “Flags” — for example g, i or gi.
- Click “Test pattern” and read the matches in the result. Use “Copy result” to keep them.
Flags and common mistakes
- g finds every match instead of stopping at the first. i ignores upper and lower case. m makes ^ and $ work on each line rather than the whole text.
- Escape special characters. A dot matches any character. To match a real full stop, write \. — the same goes for ? + * ( ) [ ].
- Greedy by default. .* grabs as much as it can. Add a question mark — .*? — to match as little as possible.
- Anchor when you mean the whole value. Without ^ and $, a pattern can match part of a longer string you meant to reject.
- Engines differ. This tool uses your browser’s JavaScript regex engine. Most patterns carry over to other languages, but check advanced features where the code will actually run.