About regex tester
A regular expression is a pattern for matching text. The tester highlights matches live so you can build and fix patterns quickly.
Building blocks
- \d matches a digit, \w a word character and \s whitespace.
- * means zero or more, + one or more and ? optional.
- ^ and $ match the start and end, and ( ) capture groups.
- Flags: g for all matches, i to ignore case, m for multi-line.
Watch out
Patterns that nest quantifiers, like (a+)+, can take enormous time on some inputs. Test with long strings before using a pattern in production.
A worked example
The pattern ^[6-9]\d{9}$ matches a 10-digit Indian mobile number that starts with 6, 7, 8 or 9. Test it on 9876543210 (match) and 5123456789 (no match). Parentheses create capture groups that you can read from the match list.
Tips
- Build a pattern in small steps, testing each addition.
- Anchor patterns with ^ and $ when you want the whole string to match.
- Be careful using regex to validate emails or HTML. Simple checks plus a confirmation email work better.
