Key Takeaways
Use a fixed input and expected-match list. A-001 B-002 should produce two complete matches. Replacing with $<team>:$2 gives A:001 B:002. Verify the replacement separately after the match-list test passes.
- The expected list contains complete matches A-001 and B-002; inspect capture values separately.Read the supporting section: Reproduce the two-ID example
- A two-digit counterexample reveals what a three-digit pattern misses.Read the supporting section: Add a counterexample that should fail
In this article
Reproduce the two-ID example
MDN’s named-group guide explains retrieving captures by name. In the regex tester, enter A-001 B-002 as the input and use the expression below with flag g.
Enter the expected complete matches as a JSON string array. After running, the team groups should be A and B and the second captures should be 001 and 002. Keeping them as text retains their padding.
(?<team>[A-Z])-(\d{3})Replacement: $<team>:$2
Expected matches: ["A-001","B-002"]Add a counterexample that should fail
Change the second ID to B-02 and keep the original expected list. The three-digit pattern misses it, so the expected-match test fails. Establish the permitted identifier length before correcting the record or revising the expression.
If the rules allow two or three digits, use \d{2,3} for that part and update the expected list to reflect the actual input. Keep both versions. Consult the JavaScript replacement rules for numbered and named substitutions and confirm syntax when moving to another application.
Keep match evidence and the final text
For configuration work, follow the semantic checks after editing. The JSON and evidence guide explains how to define what each validation step establishes.
- Inspect complete matches, ranges and groups. Check unexpected matches and empty results.
- Compare the replacement with A:001 B:002. The expected-match test checks its list; review the replacement against the intended task too.
- Download the JSON review and save the original input separately alongside it. Keep the expression and result, then rerun the small test when the expression changes.
Further reading & sources
Put the guide into practice
Open the relevant tool, preview the result and check your exported file.


