Pattern & Test Text
Replace Preview
Highlighted Matches
Match Details
Common regex patterns
| Use case | Pattern |
|---|---|
| Email address | ^[\w.+-]+@[\w-]+\.[a-zA-Z]{2,}$ |
| Indian mobile number | ^[6-9]\d{9}$ |
| URL | ^https?:\/\/[\w.-]+(\.[a-zA-Z]{2,})+[\S]*$ |
| Hex color code | ^#([0-9a-fA-F]{3}|[0-9a-fA-F]{6})$ |
| Date (YYYY-MM-DD) | ^\d{4}-\d{2}-\d{2}$ |
Related Tools
About the Regex Tester
Regular expressions are a miniature language for describing text patterns: "three digits followed by a hyphen", "an email-shaped token", "every word starting with cap". Master them and a fifty-line string-parsing function collapses into one line; misread them and a single greedy quantifier silently eats your data. This tester is where both outcomes get practised safely.
Write a pattern, choose flags (g for global, i for case-insensitive, m for multiline, s for dotall, u for Unicode), and type sample text. Matches highlight live; capture groups display separately so you can verify exactly what your parentheses collect. A replace panel applies substitutions with $1-style group references so you can preview refactors before committing them.
The engine is JavaScript (ECMAScript) regex, matching what browsers and Node use. Behaviour differences from PCRE or Python are rare but real β lookbehind and Unicode property escapes follow the modern-JS rules this tool implements.
How to use the Regex Tester
- 1 Type your pattern into the regex field, e.g. \b\d{3}-\d{4}\b.
- 2 Toggle flags: g for all matches, i to ignore case, m for line-anchored ^ and $, s so . matches newlines.
- 3 Paste sample text below; matches highlight instantly with group captures listed.
- 4 Open the replace panel, enter a substitution using $1/$2 references, and preview the transformed text.
Key features
Live match highlighting
Every match and capture group renders as you type β instant pattern feedback.
Full flag support
g, i, m, s, u toggle cleanly, matching JavaScript semantics exactly.
Capture-group panel
See what each parenthesis actually collects, including named groups.
Replace preview
Test $1 substitutions against real text before touching production code.
Safe local testing
Patterns and samples stay in your browser β fine for internal data formats.
Who uses the Regex Tester?
- Developers building validation for phones, PAN, Aadhaar, pin codes, and emails.
- Log analysis: extracting IPs, timestamps, and error codes from server output.
- Content teams bulk-fixing formatting (dates, phone numbers) before CMS migration.
- Students learning anchoring, quantifiers, and group references interactively.
- Data cleaning: normalising separators and whitespace in messy CSV exports.
Tips and best practices
- Anchor ruthlessly: ^ and $ (with m flag per line) stop patterns matching fragments you did not intend.
- Prefer lazy quantifiers (*?, +?) over greedy ones when extracting between delimiters β greedy spans swallow separators.
- Test the negative case: a regex that matches valid input should be checked against obviously invalid input too.
- For Indian phone numbers, allow +91, 0-prefix, and space/hyphen separators explicitly rather than \d{10} alone.
- Catastrophic backtracking is real: nested quantifiers like (a+)+ against adversarial input can freeze a request thread.
- Use non-capturing groups (?:...) when you need grouping but not the capture β output stays clean.
Frequently asked questions
JavaScript (ECMAScript) regex β the same engine as browsers and Node.js. Most patterns are portable to PCRE/Python, but exotic features may differ slightly.
Without g, only the first match is found; with g, every match in the text is highlighted and replaced. For validation, use anchors instead of relying on g.
Escape it with a backslash: \. matches a period, \* matches an asterisk. Inside character classes, most specials lose their power and need no escape.
Parentheses capture matched sub-text, numbered from left. In replacements, $1 inserts the first groupβs content β e.g. swapping date parts with (\d{4})-(\d{2}) β $2/$1.
Likely a flavour difference (lookbehind support, Unicode classes) or missing flags β check the m/s/u toggles first, then the escaping of slashes and backslashes.