Regex Tester Online — Free, Real-Time Regular Expression Debugger
Test and debug any regular expression instantly in your browser. Our free Regex Tester gives you real-time match highlighting directly in the test string, a full capture group inspector, one-click flag toggles (g, i, m, s), a token-by-token pattern explanation, and an automatic code generator that turns your pattern into working JavaScript, Python, or PHP — all without signing up or installing anything.
Whether you're validating email addresses, extracting dates from log files, or building complex pattern logic for a parser, you'll see exactly what your regex matches and why as you type.
How to Use the Regex Tester
- Enter your pattern — Type or paste your regular expression into the Pattern field. The
/delimiters are shown automatically; enter only the pattern itself. As you type, the Regex Explanation panel on the right immediately breaks down every token so you can see what each part does. - Toggle flags — Click
g(global),i(case-insensitive),m(multiline), ors(dotAll) to change matching behavior in real time. The pattern display next to the field updates instantly to reflect the active flags, and the match count badge refreshes immediately. - Paste your test string — Enter the text you want to match against in the Test String area. Matched portions are highlighted in yellow as you type, and a badge above the field shows the total match count. If nothing matches, a "No matches" badge appears so you know immediately the pattern needs adjustment.
- Inspect results — The Live Results panel appears below the test string as soon as matches are found. Each match is numbered and shows the matched text alongside its exact character start and end positions. Capture groups are listed separately for each match — including named groups if your pattern uses
(?<name>...)syntax. - Copy the generated code — Switch between JavaScript, Python, and PHP in the Code Generator panel and click "Copy Snippet" to get production-ready code using your current pattern, test string, and flags — ready to paste directly into your project.
- Load a library pattern — Click any entry in the Pattern Library (Email, URL, IPv4, Phone, Date, Hex Color) to instantly load the pattern and a matching sample string into the tool, then adapt it to your needs.
Regular Expressions — What They Are and Why They Matter
A regular expression is a compact notation for describing patterns in text. Invented in the 1950s by mathematician Stephen Kleene, regex engines are now built into every major programming language and are indispensable for tasks like input validation, log parsing, search-and-replace operations, and data extraction.
The key insight is that regex patterns describe structure, not specific values — \d{4}-\d{2}-\d{2} matches any ISO date without you having to enumerate every possible date. That expressiveness is what makes regex so powerful for developer tooling and text processing pipelines.
Common Use Cases
- Email validation: Use
^[a-zA-Z0-9._%+\-]+@[a-zA-Z0-9.\-]+\.[a-zA-Z]{2,}$to validate email format on the client before sending to a server. - Log file parsing: Extract timestamps, IP addresses, or error codes from large log files using anchors and character classes.
- Form input sanitization: Strip disallowed characters with a negated class like
[^a-zA-Z0-9\s]before storing user input. - URL slug generation: Convert a title to a URL-safe slug by replacing spaces and special characters:
[^\w\s-]→ remove,[\s_-]+→ replace with-. - Data extraction from HTML: Pull structured data like prices, dates, or IDs from HTML strings when a full DOM parser is overkill.
- Password policy enforcement: Verify that a password contains at least one uppercase letter, digit, and special character using lookaheads:
(?=.*[A-Z])(?=.*\d)(?=.*[\W_]).
Regex Examples
These patterns cover the most common real-world use cases. Paste the test string into the tool and type the pattern to see live results.
| Pattern | Test String | What Matches |
|---|---|---|
\d+ |
Order 1234 placed on 2024-01-15 |
1234, 2024, 01, 15 |
\b[A-Z][a-z]+\b |
Alice and Bob went to Paris |
Alice, Bob, Paris |
[a-zA-Z0-9._%+\-]+@[a-zA-Z0-9.\-]+\.[a-zA-Z]{2,} |
Contact us at hello@example.com today |
hello@example.com |
https?:\/\/\S+ |
Visit https://example.com or http://test.org |
Both full URLs |
^(\d{4})-(\d{2})-(\d{2})$ |
2024-01-15 |
Full match + 3 capture groups: 2024, 01, 15 |
#[0-9a-fA-F]{3,6} |
Primary color is #1a73e8, border #ccc |
#1a73e8, #ccc |
<.+> |
<b>bold</b> |
<b>bold</b> (entire string — greedy) |
<.+?> |
<b>bold</b> |
<b> then </b> (each tag — lazy) |
Edge case — no matches: If your pattern produces no matches, the badge above the test string shows "No matches" and no highlighting appears. This is the fastest way to confirm a pattern is wrong before moving on to debugging.
Edge case — greedy vs. lazy: On the string <b>bold</b><i>italic</i>, the greedy pattern <.+> matches the entire string from the first < to the last >. The lazy version <.+?> matches each individual tag: <b>, </b>, <i>, </i>. This is one of the most common sources of "my regex matches too much" confusion — use lazy quantifiers whenever you need the shortest match between two delimiters.
Edge case — catastrophic backtracking: The pattern (a+)+ on a string like aaaaaac forces the engine to try an exponentially growing number of backtrack paths before confirming no match. On strings longer than ~20 characters this can freeze a browser tab or server process entirely. If you notice the tool becoming unresponsive after entering a pattern, this is likely the cause — simplify nested quantifiers and always test against strings that do not match to measure worst-case performance.
Common Mistakes with Regular Expressions
Knowing what typically goes wrong saves hours of debugging. These are the mistakes developers make most often:
- Forgetting to escape special characters. The dot
.matches any character, not a literal period. To match a real dot — for example in a domain name — you must write\.. The same applies to(,),[,],{,},*,+,?,^,$, and|. - Greedy quantifiers matching too much.
.*grabs everything it can and backtracks only as much as necessary. If you're trying to extract content between two delimiters,.*will usually capture far more than you intend. Switch to.*?(non-greedy / lazy) to match the shortest possible string. - Anchors and multiline mode.
^and$match the very start and end of the entire string by default. With them(multiline) flag active, they match the start and end of each line. Forgetting to togglemwhen working with multi-line text is a frequent cause of "only the first line matches" bugs. - Forgetting the
gflag. Without the global flag, only the first match is found, even if the pattern would match dozens of times. Enablegto collect all matches — the tool shows the count in the badge so you can immediately see the difference. - Case sensitivity. By default,
[A-Z]only matches uppercase letters. Add theiflag to make the pattern case-insensitive sohello,Hello, andHELLOall match. - Catastrophic backtracking. Patterns like
(a+)+on a long non-matching string force the engine to try an exponential number of combinations before giving up. This can freeze your application. Simplify nested quantifiers and test against strings that don't match to detect performance issues early.
Frequently Asked Questions
What is a Regex Tester and how does it help developers?
A Regex Tester is a browser-based tool that lets you write a regular expression and instantly see which parts of a test string it matches — with visual highlighting, position information, and captured group details. Instead of adding console.log statements to your code and running it, you iterate on the pattern directly and only copy it to your code once it's correct. This saves significant debugging time, especially for complex patterns.
What regex flags does this tool support?
This tester supports the four most commonly used flags: g (global — find all matches rather than stopping at the first), i (case-insensitive — treat uppercase and lowercase as equivalent), m (multiline — make ^ and $ match start/end of each line, not just the whole string), and s (dotAll — make . match newline characters as well). Flags can be combined freely by clicking multiple flag buttons.
Why does my regex match more text than I expected?
Almost always, greedy quantifiers are the cause. The patterns .*, .+, \w*, and similar consume as many characters as possible before allowing the rest of the pattern to match. For example, ".*" on the string "first" and "second" matches the entire span from the first " to the last " — not each quoted string separately. Changing it to ".*?" makes the quantifier lazy and returns two separate matches. Test both versions in the tool to see the difference immediately.
What does the g flag do and when do I need it?
The g (global) flag tells the regex engine to continue searching after each match instead of stopping at the first one. Without g, calling exec() or match() in JavaScript returns only the first match — and the Live Results panel shows only one result. With g, all matches are collected and listed. You need g any time you want to count occurrences, replace all instances, or extract multiple values from a string.
What is the difference between greedy and lazy regex matching?
Greedy quantifiers (*, +, ?) match as much text as possible. Lazy (non-greedy) quantifiers (*?, +?, ??) match as little as possible. On the string <b>bold</b><i>italic</i>, the greedy <.+> matches the entire string from <b> to </i>. The lazy <.+?> matches each tag individually: <b>, </b>, <i>, </i>. Use lazy quantifiers when you need to match the shortest possible string between two delimiters.
How do regex capture groups work?
Capture groups are portions of the pattern wrapped in parentheses ( ). When a match is found, the engine records the substring that each group matched separately. Group 1 captures the content of the first (...), group 2 the second, and so on. Named groups like (?<year>\d{4}) in JavaScript let you access the captured value by name instead of index, making patterns easier to read and maintain. This tool displays both numbered and named capture groups in the Live Results panel.
Why does my regex work in JavaScript but fail in Python (or vice versa)?
Different languages implement slightly different regex engines. JavaScript uses ECMAScript regex syntax; Python uses the re module (PCRE-compatible). Key differences: Python uses (?P<name>...) for named groups while JavaScript uses (?<name>...); Python supports variable-length lookbehind while JavaScript (pre-ES2018) does not; and some Unicode escapes behave differently. Always test your pattern in the same language you'll be using in production. Use the Code Generator panel to get language-specific snippets.
How do I test a regex for email or URL validation?
Use the Pattern Library panel in the tool — it includes ready-to-use patterns for email addresses, URLs, IPv4 addresses, phone numbers, dates, and hex colors. Click any pattern to load it into the pattern field instantly. You can then paste your test cases into the test string area and adjust the pattern as needed.
Resources
- MDN Web Docs — Regular Expressions — The definitive reference for JavaScript regex syntax, flags, and the full
RegExpAPI. - regex101.com — Regex Flavors Reference — Detailed documentation on PCRE, ECMAScript, Python, and other regex engine differences.
- RegExr — Learn & Build RegEx — Interactive regex learning environment with a community pattern library and built-in cheat sheet.