Free Online Regex Tester & Debugger
Test JavaScript regular expressions against any string. See all matches, capture groups, and indices highlighted in real time. Supports all standard regex flags.
Related Tools
Frequently Asked Questions
What regex engine does this tool use?
This tool uses the JavaScript (ECMAScript) regex engine, which supports standard features like character classes, quantifiers, groups, lookaheads/lookbehinds, and named capture groups. It does not support PCRE-specific features like atomic groups.
What are capture groups?
A capture group is a portion of a pattern wrapped in parentheses that extracts a sub-match. For example, in /(\d{4})-(\d{2})-(\d{2})/ applied to "2024-01-15", group 1 is "2024", group 2 is "01", and group 3 is "15".
What does the g flag do?
The global flag (g) makes the regex match all occurrences in the input rather than stopping after the first. Without g, test() and match() only return the first match.
Testing Regular Expressions: Validation, Debugging, and Best Practices
Writing a regular expression and knowing it works correctly are two very different things. Regular expressions are notoriously easy to write in a way that seems correct but fails on edge cases — the email that contains a plus sign, the URL with an unusual path, the phone number with an international dialing code. A regex tester provides immediate visual feedback on your pattern's behavior across multiple test cases, dramatically reducing the time spent on regex debugging and preventing incorrect patterns from reaching production code.
How to Use a Regex Tester Effectively
A good regex testing workflow starts with collecting diverse test cases before writing the pattern. For an email validator, your test cases should include valid emails (simple addresses, addresses with plus signs, subdomains, new TLDs), invalid emails that should not match (missing @, missing domain, double @), and edge cases that are technically valid but unusual (quoted local parts, IP address domains). Writing out these cases explicitly forces you to clarify the exact requirements your regex must satisfy before you start writing the pattern.
With test cases in hand, develop the regex incrementally — start with the simplest pattern that handles the most basic cases, verify it works, then extend it to handle more complex cases. This step-by-step approach makes it easy to identify exactly when and why a match fails, whereas writing a complex pattern in one go and then trying to debug it against failing tests is far more difficult. Most regex testers show match highlighting in real time, so you can see exactly which parts of your test strings are being captured and by which groups.
Understanding Match Results
When a regex tester shows a match, it typically displays the full match as well as any captured groups. The full match (group 0) is the entire substring matched by the pattern. Each subsequent group (group 1, 2, 3...) corresponds to a set of parentheses in the pattern. Named groups display with their assigned names. Understanding the distinction between the full match and captured groups is essential for using regex in replacements and in code that processes match results.
Non-matches are as important as matches for validating a regex. If your pattern should not match certain inputs, verify explicitly that it does not. A common mistake is writing a pattern that matches when it shouldn't — an email validator that passes "not-an-email" as valid is worse than no validator at all, because it creates false confidence. Add negative test cases (strings that should not match) alongside positive cases and confirm the tester shows no match for them.
Regex Flags and Their Effect on Matching
Regex flags (also called modifiers) change the behavior of the matching engine. The case-insensitive flag (i) makes the pattern match without regard to letter case — /hello/i matches "Hello", "HELLO", and "hello". The global flag (g) in JavaScript causes the pattern to find all matches in the string rather than stopping after the first. The multiline flag (m) changes the behavior of ^ and $ so they match the start and end of each line rather than just the start and end of the entire string.
The dotall flag (s) — also called the single-line or DOTALL flag in other languages — makes the dot (.) match newline characters, which it does not by default. This is essential for patterns that need to match content spanning multiple lines, like multi-line HTML tags or multi-line code blocks. The extended flag (x) in languages that support it allows comments and whitespace in the pattern itself, making complex regex much more readable by allowing you to annotate each component. Always test your regex with and without each flag to understand which ones your pattern actually requires.
Lookaheads and Lookbehinds
Lookaheads and lookbehinds are zero-width assertions that match positions in the string based on what precedes or follows, without including that context in the match itself. A positive lookahead (?=...) asserts that what follows the current position matches the lookahead pattern. For example, \w+(?=ing) matches the word before "ing" in "running" — it matches "runn" without including "ing" in the match. A negative lookahead (?!...) asserts that the lookahead pattern does not follow. Lookbehinds work similarly but look backwards: (?<=\$)\d+ matches digits that follow a dollar sign.
Lookaheads and lookbehinds are particularly useful for validation — you can write conditions like "must contain at least one uppercase letter, one lowercase letter, and one digit" as a series of positive lookaheads: (?=.*[A-Z])(?=.*[a-z])(?=.*\d).{8,}. Testing these complex patterns in a regex tester with carefully designed test cases is essential, as the interaction between multiple lookaheads is not always intuitive and edge cases are easy to miss.
Converting Regex Tests to Unit Tests
Once you have validated a regex pattern with a tester tool and built confidence in its behavior, convert your test cases into unit tests in your programming language of choice. This ensures the pattern continues to work correctly as the codebase evolves and prevents regressions if the regex needs to be updated. A well-tested regex function with 10-20 test cases covering positive matches, negative matches, and edge cases is a reliable component that you can use with confidence across many contexts in your application. The test cases you built while developing the pattern in the tester become the foundation of your automated test suite with minimal additional effort.