A regular expression, or regex, is a compact pattern for matching text. A regex tester lets you type a pattern and some sample text and see the matches highlighted instantly, which turns a famously fiddly skill into fast trial and error. This guide covers the tokens and flags you will use most.
Common tokens
Most patterns are built from a small set of building blocks:
Flags
Flags change how the whole pattern behaves. The three you will reach for most are g (global — find all matches, not just the first), i (case-insensitive), and m (multiline, so ^ and $ match at each line break).
A worked example: matching an email
A simple email pattern combines several tokens:
Read left to right: one or more word characters, dots, plus, or hyphens; an @ sign; a domain of word characters and hyphens; a literal dot (escaped as \.); and a top-level domain. The ^ and $ anchor the match to the whole string. Real-world email validation is stricter, but this pattern is a solid, readable starting point.
How to use the regex tester online
- Type or paste your pattern.
- Add flags such as g or i.
- Paste sample text to test against.
- Watch matches highlight, and refine the pattern until it fits.
Why a pattern might not match
- You forgot to escape a special character — a literal dot must be written as \.
- Anchors ^ and $ are too strict for text that has surrounding characters.
- You expected multiple matches but did not set the g flag.
- Case matters and the i flag is missing.
FAQ
Q: What do the flags g, i and m do?
A: g finds every match, i ignores case, and m makes ^ and $ match at each line rather than only the start and end of the whole text.
Q: How do I match an email address?
A: A readable pattern is ^[\w.+-]+@[\w-]+\.[\w.-]+$. Fully RFC-compliant email regex is far more complex, so most apps use a simple pattern plus a confirmation step.
Q: Why is my regex not matching?
A: The usual causes are an unescaped special character, over-strict anchors, or a missing g or i flag. Testing against sample text quickly reveals which.