Guide
How to Write and Test Regular Expressions
Learn how regex patterns work, how to test them safely, and practical patterns for everyday text tasks.
A regex tester lets you write a regular expression, run it against sample text, and see matches and capture groups highlighted in real time. It is the fastest way to learn, debug, and refine patterns.
Regex basics
A regular expression describes a pattern in text. Literal characters match themselves; metacharacters like ., *, +, ?, [], (), and \ have special meaning. For example, \d matches a digit, \w a word character, . any character, and * means "zero or more of the previous".
Common building blocks
- \d+ — one or more digits.
- \w+ — one or more word characters (letters, digits, underscore).
- [a-z] — any lowercase letter.
- ^...$ — anchors to the start and end of the string.
- (... ) — a capture group you can extract.
- \b — a word boundary.
How to test a regex
- Enter your pattern and any flags (g for global, i for case-insensitive, m for multiline).
- Paste sample text that should and should not match.
- Read the highlighted matches and the list of capture groups.
- Refine the pattern and re-test until it matches exactly what you want.
Examples
The pattern \b\w+@\w+\.\w+\b matches simple email-like strings. \d{4}-\d{2}-\d{2} matches dates in YYYY-MM-DD form. ^(Yes|No)$ matches a whole line that is exactly "Yes" or "No". Test each against mixed sample text to confirm it catches the right things and ignores the rest.
When a regex tester is useful
- Building validation patterns for forms (emails, phones, dates).
- Debugging a pattern that matches too much or too little.
- Learning regex with immediate visual feedback.
- Extracting or replacing patterns in data cleanup.
Put it into practice
Use the Regex Tester right now — free, in your browser, no sign-up required.
Try the Regex TesterMore guides
- How to Unscramble Letters Into Words
- How to Find Anagrams of Any Word
- How to Count Words, Characters and Reading Time Accurately
- How to Find Words by Pattern, Length and Letters
- How to Use a Random Word Generator for Games, Writing and Brainstorming
- How to Count Characters (With and Without Spaces)
- How to Convert Text Between Cases (UPPER, lower, Title, camelCase and More)
- How to Clean Up Messy Text (Spaces, Line Breaks and Whitespace)
Related free tools
More free online utilities that pair well with this one — same-category tools for the same task, plus handy extras from other categories.
More developer & security tools
- Cron Expression GeneratorBuild cron expressions & see next runs
- Base64 Encoder / DecoderConvert plain text or images to Base64 strings
- Hash GeneratorGenerate MD5 & SHA-256 hashes from text
- JWT DecoderDecode JSON Web Token header & payload
- Curl-to-Code ConverterConvert curl commands to fetch, Python & PHP