Regex Tester for Code Review
Stop guessing whether a regex works. Test patterns against real sample strings during code review — verify edge cases, catch backtracking bugs, and validate matches before merge. Instant results, zero sign-up.
🧪 Try the Regex Tester — FreeThe Problem: Code Reviewers Approve Regex They Haven't Actually Tested
Regular expressions are one of the most dangerous things to approve in a pull request without testing. Unlike a typical code change — where you can reason about control flow, read the logic, and spot bugs through static analysis — a regex pattern is a dense, compact specification where a single misplaced character can silently invert the matching behavior. A missing caret anchor, an overly greedy quantifier, or a character class that's one range wider than intended: these bugs are nearly invisible to the naked eye during code review, yet they cause validation failures, data corruption, and security vulnerabilities in production. The Regex Tester on ToolStand solves this by letting you paste both the regex pattern and a collection of test strings — and see exactly what matches, what doesn't, and what capture groups are produced — all in real time, directly in your browser.
Most code review workflows treat regex as a black box. The reviewer reads the pattern, maybe squints at it for thirty seconds, recognizes the general shape of it, and approves with a mental note of "looks about right." This is not negligence — it's a rational response to the tooling gap. Without a regex tester at their fingertips, the reviewer would need to open a separate IDE, create a temporary file, write a test harness, run it, and compare results against the expected behavior. That's fifteen minutes of context-switching for a single regex. Multiply that across a team reviewing dozens of PRs per week, and the friction is simply too high. The result: regex bugs sail through code review undetected, only to be discovered when a customer reports that their valid email address was rejected, or when the security team notices that a sanitization pattern has been silently failing for six months.
What makes this especially dangerous is that regex bugs are often silent in their failure mode. A validation regex that is too permissive doesn't crash — it just lets bad data through, quietly polluting your database. A parsing regex with a missing anchor doesn't throw an exception — it just matches in unexpected positions, extracting the wrong substring from your log lines. These failures are rarely caught by unit tests because developers tend to write tests that verify the happy path: they test that valid inputs pass and invalid inputs are rejected, but they rarely test the boundary where "almost valid" inputs should be rejected but are accidentally accepted because of a missing word boundary or an overly permissive character class. The Regex Tester makes it trivial to test these boundary cases during review.
How the Regex Tester Transforms Code Review
The Regex Tester is a split-pane tool: on the left, you enter your regex pattern with optional flags; on the right, you enter one or more test strings. The tool highlights matches in real time — showing you exactly which portion of each test string matches, which capture groups are populated, and what the matched text contains. There is no build step, no test framework, no temporary file. You paste, you type, and the results appear instantly. This instant feedback loop turns regex review from a static reading exercise into an active, evidence-driven evaluation.
The workflow is designed for the speed and cadence of real code review. When you encounter a regex in a pull request, you copy the pattern from the diff, paste it into the Regex Tester, and immediately start typing test strings that probe the pattern's edge cases. Does the empty string match? What about a string that is entirely whitespace? What happens with Unicode characters outside the ASCII range? Does the pattern handle trailing newlines correctly? What about an input that is 10,000 characters long — does the pattern cause catastrophic backtracking and freeze the browser? These questions that would take twenty minutes to answer with a unit test framework can be explored in under a minute with the Regex Tester, making it practical to test every regex in every PR you review.
The tool also reveals structural information about the match that static reading cannot. You can see which capture groups are populated and with what content. If the PR author intended group 2 to capture the domain name but group 2 is consistently empty across your test strings, you have found a bug before the code even hits the main branch. If the pattern uses named capture groups, the Regex Tester displays them by name, making it easy to verify that the author's naming matches the intended semantics. These are insights that no amount of staring at a regex pattern in a diff viewer can produce.
Verifying Edge Cases: The Real Value of a Regex Tester in Review
The difference between a regex that "looks correct" and one that is actually correct lives entirely in the edge cases. Consider a common review scenario: a developer submits a PR with a regex for validating phone numbers. The pattern looks plausible at first glance — digits, optional parentheses, maybe a hyphen or two. But does it accept international formats with a leading plus sign? Does it reject a string of twenty consecutive digits? Does it match a phone number embedded in the middle of a longer string when it should require the entire string to be a phone number? Without testing, these questions are speculation. With the Regex Tester, they are answered in seconds.
Here is a concrete example. You are reviewing a PR that adds the pattern /^\(?\d{3}\)?[-.\s]?\d{3}[-.\s]?\d{4}$/ for US phone number validation. At first glance, this looks solid — it handles optional parentheses around the area code, optional separators, and anchors at both ends. But paste it into the Regex Tester and try a few test strings. The string "(555) 123-4567" matches, as expected. The string "555-123-4567" also matches. Good. Now try "(555 123-4567" — a malformed input with an opening parenthesis but no closing one. It does not match, which is correct. But try "5551234567" — ten consecutive digits with no separators. It matches, which may or may not be desired depending on the application's UX requirements. Now try "15551234567" — eleven digits with a leading country code. It does not match, which means international users cannot enter a US country code prefix. And try "(555)-123-4567" — area code in parentheses followed by a hyphen. It matches, but the parentheses and hyphen together look odd visually. These are not hypothetical edge cases — they are real inputs that real users will type into your form, and the Regex Tester lets you discover them during code review rather than during the post-deploy bug triage.
Catching Catastrophic Backtracking Before It Reaches Production
Catastrophic backtracking is the nightmare scenario of regex performance. A pattern with nested quantifiers — such as /(a+)+b/ — can cause a regex engine to explore an exponential number of matching paths when given certain inputs. The result is a frozen application thread, an unresponsive server, or a browser tab that hangs indefinitely. These patterns are surprisingly common in production code because they look innocent: a developer writes a regex to match a repeating pattern with internal repetition, not realizing that the combination of nested greedy quantifiers creates an exponential worst-case matching time. During code review, catastrophic backtracking vulnerabilities are nearly impossible to detect by reading the pattern alone, but the Regex Tester makes them trivially observable.
Here is how to test for backtracking with the Regex Tester. Paste the pattern /([a-zA-Z0-9]+)*@/ — a simplified email local-part matcher that looks innocent but contains the dangerous (...)+* pattern with a nested quantifier inside a group that is itself quantified. Now enter a test string: "aaaaaaaaaaaaaaaaaaaaaaaaaaaa!" — a long string of the letter "a" followed by a character that will never match the @ symbol, forcing the engine to explore every possible backtracking path before failing. When you test this in the Regex Tester, you will notice a perceptible delay — the browser tab may freeze for several seconds as the regex engine exhaustively backtracks through every possible way to partition the "a" characters across the group repetitions. In a real production scenario with longer input strings, this delay becomes a denial-of-service vector. Flag it in your review: the pattern needs to be rewritten with an atomic group (?>[a-zA-Z0-9]+)* or by removing the nested quantifier entirely. Without the Regex Tester, you would have approved this pattern, and it would have shipped to production.
Even patterns that are not vulnerable to full catastrophic backtracking can exhibit poor performance on long inputs that the Regex Tester reveals instantly. A pattern like /^.*\/\/.*$/ to match lines containing a comment — seemingly straightforward — uses two greedy dot-star quantifiers that force the engine to scan to the end of the string and backtrack. On a 100-character line this is negligible; on a 100,000-character minified JavaScript file it can take hundreds of milliseconds per match. Testing with long strings in the Regex Tester during code review surfaces these performance cliffs immediately, letting you suggest a more efficient alternative like /\/\/.*$/ that anchors on the literal comment marker without the leading wildcard.
Testing Against Production Data Samples Without Risk
One of the most powerful code review techniques is testing a new or modified regex against real data from your production environment. A pattern that passes all synthetic test cases can still fail on real user input, which is messier, more varied, and less predictable than anything a developer types by hand. The Regex Tester supports this workflow because it runs entirely client-side: you can copy a sample of production data — anonymized or redacted as your security policy requires — and paste it directly into the test string panel. The pattern and the data never leave your browser, meaning you can test against realistic inputs without exposing sensitive information to a third-party service.
Consider a team maintaining a log aggregation pipeline. A PR modifies the regex that parses Apache combined log format entries to extract a new custom field. The developer tested it against five hand-written log lines and all five matched. During code review, you copy fifty real log lines from yesterday's production logs — redacting IP addresses and user agents if needed — and paste them into the Regex Tester. You immediately discover that three of the fifty lines fail to match because they contain request URLs with query parameters that include characters the character class does not account for. Without testing against real data, this bug would have been discovered after deployment, when the log pipeline silently dropped 6% of entries. With the Regex Tester, you leave a review comment with the exact failing log line patterns, and the author fixes the regex before merge.
This same workflow applies to any regex that processes user-generated content: form validators, input sanitizers, URL routers, data scrapers, and configuration file parsers. Synthetic test cases, no matter how carefully crafted, cannot anticipate the full diversity of real-world input. The Regex Tester bridges the gap by making it safe and fast to test against production samples directly in the browser during code review.
Comparing Behavior Across Different Input Formats
A regex that works perfectly for one input format may fail silently for another. During code review, it is essential to test the pattern against every input format the application is expected to handle. The Regex Tester makes this comparison trivial: you can paste multiple test strings — each representing a different input format — and see side by side which ones match, which ones don't, and what capture groups are populated for each.
For example, a PR introduces a regex to extract version numbers from user-agent strings. The pattern is designed to match formats like "Chrome/120.0.0.0", "Firefox/115.0", and "Safari/17.0". During review, you paste all three into the Regex Tester along with less common formats: "Chrome/120.0.6099.109" (four-part version with a build number), "Mobile Safari/17.0" (browser name with a space), "curl/8.4.0" (lowercase, different tool), and "Mozilla/5.0 (compatible; Googlebot/2.1)" (bot user-agent with a different structure). The Regex Tester shows you instantly that the pattern correctly matches Chrome, Firefox, and Safari, but fails on the four-part version number because the quantifier is too restrictive, fails on the space-containing browser name because the character class does not include whitespace, matches curl but captures the wrong group, and fails entirely on the Googlebot format. These are actionable findings that let you request targeted changes before the PR is merged.
Leaving Informed, Evidence-Backed Review Comments
The single biggest improvement the Regex Tester brings to code review is the quality of the feedback you can leave. Instead of a vague comment like "is this regex correct?" or "please double-check the pattern," you can leave a comment backed by specific test results. You can list the exact input strings that unexpectedly matched or failed to match. You can note which capture groups are misaligned with the author's documented intent. You can report that a particular input causes a multi-second evaluation delay, suggesting a backtracking vulnerability. This transforms regex review from a subjective, gut-feel process into an objective, evidence-driven evaluation.
Good code review comments are specific, actionable, and kind. The Regex Tester enables all three: specific because you can quote exact test strings and their outcomes; actionable because you can suggest precise pattern changes that would fix the demonstrated issue; and kind because you are providing concrete data rather than subjective criticism. "I tested the pattern against 'abc@def' and it matched, but it should reject addresses without a TLD" is a much more constructive comment than "this email regex looks wrong." The author can immediately reproduce your finding, understand the issue, and implement the fix — no back-and-forth clarification needed.
Quick Start: Testing a Regex During Code Review
- Open the Regex Tester on ToolStand in a new browser tab. No download, no account, no setup required.
- Paste the regex pattern from the PR diff into the pattern field. Include flags like
/g,/i, or/mif the code uses them — the Regex Tester applies them exactly as the runtime would. - Enter test strings in the test panel. Start with the obvious valid and invalid cases, then add edge cases — empty strings, boundary values, long inputs, Unicode, and deliberately malformed strings that probe the pattern's limits.
- Observe match highlights in real time. The Regex Tester shows exactly which portion of each test string matches and which capture groups are populated, with group names if the pattern uses named groups.
- Check for backtracking by testing a long string designed to trigger exponential matching. If the result lags, flag the pattern's nested quantifiers in your review.
- Leave an evidence-backed review comment quoting specific test strings and their match outcomes. Link to the Regex Tester so the author can reproduce your findings instantly.
Common Questions from Code Reviewers
"How many test strings should I test against during a review?" Aim for at least eight to twelve test strings covering distinct categories: valid typical inputs, valid edge cases (boundary lengths, unusual but legal characters), clearly invalid inputs, borderline inputs that should arguably be rejected, an empty string, a whitespace-only string, a very long string for performance testing, and at least one input that probes a specific concern you have about the pattern's structure. This takes about two minutes and catches the vast majority of regex bugs that slip through review.
"What if the PR uses a regex flavor different from JavaScript?" The Regex Tester uses your browser's JavaScript regex engine, which supports the ECMAScript regex grammar. For most common use cases — validation, parsing, log extraction, URL routing — the differences between JavaScript regex and other flavors (PCRE, Python, Java) are minimal for the patterns you typically encounter in application code. If the PR targets a backend runtime with significantly different regex semantics (e.g., .NET balancing groups or Ruby's unique anchor behavior), note that in your review and suggest the author document any flavor-specific assumptions. For the 95% case of standard patterns with anchors, quantifiers, character classes, and groups, the Regex Tester is fully applicable.
"Does the Regex Tester support Unicode and international text?" Yes. The Regex Tester supports Unicode input strings and patterns with Unicode property escapes (\p{L}, \p{N}, etc.), Unicode flag (/u), and full multi-byte character handling. This is essential for code review of applications that handle international user input — names, addresses, messages — where ASCII-only patterns can silently reject valid non-Latin text. Test with real Unicode samples: Chinese characters, Arabic script, emoji, accented Latin characters, and RTL text to ensure the pattern handles them correctly.