A regular expression can match the example you expected and still accept several inputs you did not intend. Useful testing includes both positive and negative cases, deliberate flag choices, and a check of exactly what was captured. A colored match or a nonzero result count is not enough to establish a reliable validation rule.
This guide uses the ToolsOnDuty Regex Tester to inspect a small product-code pattern. The real browser screenshots show two matches with case-sensitive rules and three with case-insensitive rules. We also checked the exported JSON, capture groups, match indexes and the response to an invalid expression.
Enter a pattern without JavaScript string escaping
Open Regex Tester and enter the pattern below in Expression. Enter only the expression, without surrounding slash delimiters or appended flags; the workspace displays those separately. In this field, a digit class is written as backslash followed by d. Inside a JavaScript quoted string, that backslash generally needs escaping, which is a different input context.
The example searches for two uppercase letters, a hyphen and exactly three digits at word boundaries. Its two parenthesized groups capture the letter prefix and numeric suffix separately. It is a deliberately small demonstration, not a universal product-code specification. Adjust the rules to the actual identifiers your application uses.
\b([A-Z]{2})-(\d{3})\bUse positive and negative examples in the same test
Paste the following line into Test data. AB-123 and XY-789 satisfy the uppercase rule. ab-456 differs only in case, while AB-12 contains too few digits. Start with g selected and i, m, s, u and y unselected so that the case comparison is easy to interpret.
Results update as you type; there is no separate Run button for this workflow. With the initial flags, the inspector should contain AB-123 at index 0 and XY-789 at index 14. AB-12 must remain unmatched. Check the individual records, not only the header's match count, before changing the expression.
AB-123 ab-456 XY-789 AB-12Turn on ignore case and inspect the groups
Select i (ignore case). The inspector now includes ab-456 at index 7, giving three matches at indexes 0, 7 and 14. The invalid short code still does not match because ignoring case does not change the required digit count. This isolates the effect of one flag instead of changing the pattern and several options simultaneously.
The first record reports group 1 as AB and group 2 as 123. The lowercase record preserves its captured text as ab and 456; the i flag does not uppercase the source. JavaScript indexes are zero-based UTF-16 code-unit offsets. They are not byte positions and may differ from visually counted characters when the source includes emoji or other multi-unit characters.
Understand searching versus validating a whole value
Word boundaries allow the pattern to find a code within a longer message. They do not require the entire field to consist of one valid code. For whole-value validation, anchors are often needed, along with an explicit decision about surrounding whitespace and accepted character ranges. Test your complete rule against the same environment that will enforce it.
Add counterexamples such as AB-1234, a leading extra letter, unexpected punctuation and an empty value. If a case-insensitive rule is intentional, keep lowercase examples in the test set instead of relying on memory. A regex match also does not prove that a referenced account, order or product actually exists; that requires separate application checks.
^([A-Z]{2})-(\d{3})$Choose flags deliberately and note this workspace's behavior
The m flag changes how start and end anchors treat line boundaries, while s allows a dot to match newline characters. Neither is needed for the single-line example. The u flag changes Unicode-aware interpretation, and y uses sticky matching at the current search position. These options are not interchangeable ways to find more results.
The current ToolsOnDuty runner collects matches globally even if the visible g checkbox is cleared. We verified that the example still exported three matches with i alone displayed. Keep g selected for this guide, and do not use this workspace to demonstrate the first-match-only behavior of every JavaScript matching API. Reproduce flag-sensitive behavior in your target application as well.
Export the results and check what the report contains
Click Export matches while the gi result is visible. The downloaded regex-match-report.json includes the pattern, displayed flags, source length, match count and an array of matches with indexes and groups. Our test reported sourceLength 26 and matchCount 3, and the exported values exactly matched the inspector.
The report is not a redacted audit file. Matched strings and capture groups can contain email addresses, account numbers or other private information even though the complete test source is not included. Review the JSON before sharing it, and provide a small anonymized fixture when asking another developer to reproduce a problem.
Troubleshoot safely with short, trusted test data
An unmatched opening square bracket produces an invalid-pattern error rather than a normal empty match list. If a valid pattern finds nothing, inspect case, boundaries, escaping and the exact source characters. Distinguish a syntax error from a rule that simply does not accept the current example.
Matching runs synchronously in the browser. Expensive patterns against large inputs can make the page unresponsive; the match-collection guard is not a guaranteed execution timeout. Begin with short trusted examples and avoid testing unknown complex expressions against large confidential logs. Keep your source elsewhere before resetting or reloading the workspace.
Try the related tools
Apply the steps from this guide directly in your browser.
Frequently asked questions
Should I enter the surrounding slashes and flags in Expression?
No. Enter the pattern body in the field and choose flags with the checkboxes. The workspace supplies the surrounding display delimiters.
Does ignore case change the case of captured text?
No. It changes matching rules. In the example, the lowercase match still exports ab as its first capture group.
Does clearing g guarantee that only one match is returned?
Not in the current workspace. Its runner collects matches globally even when g is not visibly selected. Test API-specific non-global behavior in your own JavaScript environment.
Is the exported JSON safe to share without review?
No. Although it omits the complete source, matched text and capture groups may still expose sensitive values. Review or anonymize the report first.
