DevBolt
Processed in your browser. Your data never leaves your device.

How do I test a regular expression online?

Enter your regex pattern and test string, and see all matches highlighted in real time. The tool supports JavaScript regex flags (g, i, m, s, u), shows capture groups, and explains what each part of your pattern does. Everything runs client-side in your browser.

Match email addresses
Input
Pattern: [\w.-]+@[\w.-]+\.\w+
Text: Contact us at hello@devbolt.dev or support@example.com
Output
Match 1: hello@devbolt.dev
Match 2: support@example.com
← Back to tools

Regex Tester

Test regular expressions in real time with match highlighting and capture groups.

//g

Matches (0)

Enter a pattern and test string to see matches

Tips & Best Practices

Common Pitfall

Catastrophic backtracking can freeze your app

Patterns like (a+)+ or (a|a)* cause exponential backtracking on non-matching input. A 25-character string can take minutes to process. Use atomic groups or possessive quantifiers (a++ in Java/PCRE) to prevent this. In JavaScript, use the 'v' flag with set notation where possible.

Pro Tip

Test edge cases, not just happy paths

An email regex that matches test@example.com might also match test@.com or @example.com. Always test with: empty strings, strings with only whitespace, extremely long input (>1000 chars), Unicode characters, and inputs that almost-but-don't-quite match your pattern.

Real-World Example

Named capture groups make regex maintainable

Instead of (\d{4})-(\d{2})-(\d{2}) where you access groups by index, use (?<year>\d{4})-(?<month>\d{2})-(?<day>\d{2}). In JavaScript: match.groups.year. Named groups act as documentation and survive refactoring when you add or remove groups.

Security Note

Never use regex for HTML parsing

Regular expressions cannot handle nested structures. A regex to extract href attributes will break on nested quotes, CDATA sections, comments containing tags, and self-closing elements. Use a proper HTML parser (DOMParser in browsers, cheerio/jsdom in Node.js).

Frequently Asked Questions

How do I test a regular expression online?
Enter your regex pattern in the pattern field and your test string in the text area. Matches are highlighted in real time as you type. DevBolt's Regex Tester shows all matches with their captured groups, positions, and full match details. You can toggle flags like global (g), case-insensitive (i), multiline (m), dotAll (s), and unicode (u). The tool uses JavaScript's native RegExp engine, so results match exactly what you would get in Node.js, browsers, and TypeScript. Sample patterns are included for common use cases like email, URL, and date validation.
What does the g flag do in regex?
The global (g) flag tells the regex engine to find all matches in the input string, not just the first one. Without the g flag, the regex stops after the first match. With it, methods like String.matchAll() and RegExp.exec() iterate through every occurrence. For example, /\d+/ without g on '123 abc 456' matches only '123', but /\d+/g matches both '123' and '456'. The g flag is essential for search-and-replace operations, counting occurrences, and extracting all instances of a pattern from text.
How do I match an email address with regex?
A practical email regex is /^[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,}$/. This matches the local part (letters, digits, dots, underscores, percent, plus, hyphen), the @ symbol, the domain (letters, digits, dots, hyphens), and a TLD of 2 or more letters. Note that the full RFC 5322 email spec is extremely complex — no simple regex covers all valid email addresses. For production use, combine a reasonable regex for client-side UX feedback with server-side validation that sends a confirmation email. The regex above covers 99.9% of real-world email addresses.

Related Inspect Tools