Skip to main content

JavaScript Regex Tester: Matches, Groups, Replace Preview

Test JavaScript regex patterns locally, highlight matches and capture groups, preview replacements, and build patterns step-by-step (educational).

Loading calculator...
Loading educational content...

Frequently Asked Questions

Is my test text sent anywhere?

No. Your test text is processed entirely locally in your browser. It is never sent to any server or external service. The AI assistant only receives derived statistics like match counts and pattern information—never your actual text.

Why do I only get one match?

You're likely missing the global (g) flag. Without it, JavaScript regex only returns the first match. Add 'g' to your flags to find all matches in the text.

Why is my regex slow or hanging?

This is often caused by 'catastrophic backtracking.' Patterns with nested quantifiers like (a+)+ or multiple greedy wildcards can cause exponential matching time. Try making your pattern more specific, using lazy quantifiers (*?, +?), or breaking it into simpler parts.

What's the difference between match and test?

regex.test(string) returns a boolean (true/false) indicating if the pattern exists in the string. regex.exec(string) or string.match(regex) returns the actual match details including captured groups and positions. Use test() for simple yes/no checks; use exec/match when you need the matched content.

How do capture groups work?

Capture groups are created with parentheses (). Each group captures the matched text, which you can reference as $1, $2, etc. in replacements. For example, /(\d{3})-(\d{4})/ on '555-1234' captures '555' as $1 and '1234' as $2. Named groups use (?<name>...) syntax and can be referenced as $<name>.

Does JavaScript support lookbehind?

Yes, modern JavaScript (ES2018+) supports both lookahead and lookbehind assertions. Lookahead: (?=...) positive, (?!...) negative. Lookbehind: (?<=...) positive, (?<!...) negative. However, older browsers may not support lookbehind—check compatibility if targeting older environments.

What's the difference between greedy and lazy quantifiers?

Greedy quantifiers (*, +, {n,m}) match as much as possible, then backtrack if needed. Lazy quantifiers (*?, +?, {n,m}?) match as little as possible, expanding only when needed. For example, on '<div>content</div>', the pattern <.*> (greedy) matches the entire string, while <.*?> (lazy) matches just '<div>'.

How do I match a literal special character?

Escape special characters with a backslash. Special regex characters are: . * + ? ^ $ { } [ ] \ | ( ). For example, use \. to match a literal period, \$ for a dollar sign, and \\ for a backslash.

What does the 'u' flag do?

The Unicode (u) flag enables proper handling of Unicode characters, including surrogate pairs for characters outside the Basic Multilingual Plane. With 'u', you can use \p{...} Unicode property escapes like \p{Letter} or \p{Emoji}. It's recommended for internationalized applications.

Can I use regex to validate email addresses?

While regex can check email format, the truly correct email validation regex is extremely complex. For practical purposes, a simple pattern like /^[^\s@]+@[^\s@]+\.[^\s@]+$/ catches most obvious errors. For production, consider using a dedicated email validation library or simply sending a verification email.

Explore More Tech & Dev Utilities

Calculate file transfer times, subnet configurations, password entropy, and more with our suite of developer tools.

How helpful was this calculator?

Regex Tester & Builder: JS Matches + Replace Preview