Regex Tester & Debugger

Agarapu Ramesh — Editor and content reviewer

What This Tool Does

This regex tester evaluates your regular expression against a test string and highlights every match in real-time. It supports all JavaScript regex flags (g, i, m, s, u, y), shows capture groups for each match, and reports match positions. Perfect for debugging patterns before using them in code.

Inputs Explained

How It Works

The tool constructs a JavaScript RegExp with your pattern and flags, applies it to your test string with String.matchAll, and wraps every match in a highlighted span. Capture groups are extracted from each match and displayed with their position indices. Replacement preview uses String.replace.

Formula / Logic Used

re = new RegExp(pattern, flags) matches = [...text.matchAll(re)] highlight = text.replace(re, m => `${m}`)

Test and debug regular expressions with live match highlighting and capture group detail.

Step-by-Step Example

Pattern: \b\w+@\w+\.\w+\b | Flags: gi

Test: Contact [email protected] or [email protected] today.

Matches: 2 — [email protected] (at index 8), [email protected] (at index 29).

With replacement [EMAIL]: Contact [EMAIL] or [EMAIL] today.

Use Cases

Assumptions and Limitations

Disclaimer: Processing runs entirely in your browser. Your patterns and test strings are never uploaded.

Frequently Asked Questions

1: How do I write a regex for HTML tag matching?

For simple checks, you can match a basic HTML tag with something like <([a-z][a-z0-9]*)\b[^>]*> in case-insensitive mode. That finds an opening tag name and optional attributes. However, regex is not reliable for fully parsing HTML because HTML can contain nested tags, comments, scripts, malformed markup, and quoted > characters. For real extraction or validation, use an HTML parser. Use regex only for lightweight tasks, such as finding likely tags in a snippet, cleaning controlled text, or quick editor searches.

2: How do I write a regex for a date format (YYYY-MM-DD)?

A simple regex for YYYY-MM-DD is ^\d{4}-\d{2}-\d{2}$. This checks the shape, such as 2026-05-06, but it still allows impossible dates like 2026-99-99. A stronger pattern is ^\d{4}-(0[1-9]|1[0-2])-(0[1-9]|[12]\d|3[01])$, which limits month and day ranges. Even then, it does not fully validate leap years or month-specific days. My usual advice is: use regex to check the format, then use a date library or built-in Date validation for actual calendar correctness.

3: How do I test JavaScript regex with live highlighting?

Paste your test text into the Regex Tester, enter the pattern, and choose JavaScript-style flags such as g for global, i for case-insensitive, and m for multiline. Live highlighting shows each match immediately, which makes it easier to see whether your expression is too broad or too narrow. Add sample text that includes normal cases, edge cases, and things that should not match. If your regex has groups, review the captured values too. This is much faster than guessing inside application code.

4: What is a positive lookahead in regex?

A positive lookahead checks that something appears next, without consuming it as part of the match. The syntax is (?=pattern). For example, \w+(?=:) matches a word only when it is followed by a colon, but the colon is not included in the match. Lookaheads are useful for password rules, conditional matching, and finding text before a marker. The key idea is simple: "match this position only if the next characters satisfy this rule." It is powerful, but overusing it can make regex harder to maintain.

5: What does `\b` mean in regex?

In regex, \b means a word boundary. It does not match a visible character; it matches a position between a word character and a non-word character. For example, \bcat\b matches "cat" as a separate word, but not the cat inside "catalog". This is useful for search-and-replace tasks where you only want whole words. One thing to remember: "word character" usually means letters, digits, and underscore in JavaScript regex, so behavior with non-English scripts may require Unicode-aware patterns.

6: How do I replace text using regex with back-references?

Back-references let you reuse captured parts of a match in the replacement. First put the part you want to keep inside parentheses. For example, with pattern (\w+) (\w+) and replacement $2, $1, the text "Asha Rao" becomes "Rao, Asha" in JavaScript-style replacement. This is great for reformatting names, dates, IDs, or log lines. Always test on sample data first, because one extra capturing group changes the numbering. If you do not need to capture a group, use a non-capturing group like (?:...) instead.

7: Why is my regex matching too much?

Most of the time, this happens because a quantifier is greedy. For example, .* tries to take as much text as possible while still allowing the pattern to match. If you wanted the shortest match, use a lazy quantifier such as .*? or make the character class more specific, like [^<]* for text before a tag. Anchors also help: ^ starts at the beginning and $ ends at the end. In a tester, add several examples and watch where the highlight starts and stops.

Sources and References

Related Calculators

Find & ReplaceEmail ExtractorJSON FormatterCase ConverterURL EncoderHTML Entities