Regex Tester — Build and Test Regular Expressions Quickly
Regular expressions are one of the most powerful text-processing tools — and one of the most intimidating to write. The Regex Tester on THRJ gives you a live environment to write, test, and debug patterns with real-time match highlighting and replacement previews. Open the Regex Tester.
What Is a Regular Expression?
A regular expression (regex) is a sequence of characters that defines a search pattern. It can match email addresses, phone numbers in many formats, line anchors, repeated patterns, optional groups, and much more. Regex is supported in JavaScript, Python, Java, Go, Ruby, and many editors and CLI tools.
Overview
Regex Tester provides a live environment to write regular expressions, test them against sample text, and visualize matches. It shows capture groups, replacement previews, and supports common flags like g, i, m, s, and u.
Quick Steps
- Open the Regex Tester page: /regex-tester.
- Enter or paste sample text into the input area.
- Type your regular expression into the pattern field.
- Toggle flags like
i(ignore case) org(global) as needed. - See matches highlighted live and use replacement preview to test substitutions.
Features
- Live highlighting of matches and capture groups
- Replacement preview to test substitutions safely
- Flag toggles and common pattern snippets
- Export your pattern and sample text for sharing
Understanding Regex Flags
| Flag | Symbol | Effect |
|---|---|---|
| Global | g | Find all matches, not just the first |
| Ignore case | i | Match regardless of case |
| Multiline | m | ^ and $ match line starts/ends |
| Dot all | s | . matches newline characters too |
| Unicode | u | Enable full Unicode matching |
Common Regex Patterns Reference
| Pattern | Purpose | Example |
|---|---|---|
| ^[a-zA-Z0-9._%+\-]+@[a-zA-Z0-9.\-]+\.[a-zA-Z]{2,}$ | Email address | user@example.com |
| https?:\/\/[^^\s]+ | URL (http or https) | https://example.com/path |
| \+?[\d\s\-().]{7,15} | Phone number (flexible) | +1 (555) 123-4567 |
| \b\d{4}-\d{2}-\d{2}\b | ISO date (YYYY-MM-DD) | 2024-07-15 |
| ^\s*$ | Blank line | Lines with only spaces |
How to Use Replacement Mode
Replacement preview lets you test String.replace() or sed-style substitutions before applying them.
Example — Normalize dates:
Pattern: (\d{4})-(\d{2})-(\d{2})
Replacement: $2/$3/$1
Result: 2024-07-15 → 07/15/2024
Step-by-Step Scenarios
Validating a form field pattern
- Paste sample values into the input area.
- Write your validation regex (e.g., ZIP code).
- Toggle the
gflag to see all matches. - Adjust until only valid entries are highlighted.
Cleaning up copied data
- Paste messy text from a spreadsheet.
- Write a pattern to match unwanted prefixes.
- Use replacement mode with an empty replacement to strip them out.
- Copy the cleaned result.
Tips & Common Mistakes
- Start simple and add complexity progressively.
- Escape literal special characters like
.,*,+,?,(,). - If you see no matches, check your flags — especially
g. - Use named capture groups (
(?<name>...)) for clarity in complex replacements.
Privacy
All processing is local to your browser. Your patterns and test text never leave your device. Avoid pasting sensitive data if you are concerned about clipboard history.
Frequently Asked Questions
Do I need programming knowledge?
No. The tester is usable by developers and non-developers alike. The quick-reference above covers common use cases.
What's the difference between a match and a capture group?
A match is the full text the pattern matched; capture groups (parentheses) extract sub-parts of that match.
Published by THRJ Tech