How to use GitHub Copilot to fix regex captures
Copilot traced empty NonBacktracking captures to trailing-newline handling, added anchor regression tests and revised the .NET fix through human review.
Original prompt
Shared by the source author. See source notes for context.
Newline causes empty regex capture groups when NonBacktracking in dotnet 9 and above
Reach people exploring AI agents
See placements →What happened
Copilot traced empty NonBacktracking captures to trailing-newline handling, added anchor regression tests and revised the .NET fix through human review; the pull request merged into dotnet/runtime main.
Reported by Copilot (on behalf of stephentoub) on GitHubHow the agent did it
- Investigated input-reader/capture state.
- Restricted special newline handling to relevant end-anchor semantics.
- Added anchor-combination regression cases and handled review concerns.
Where a person stepped in
Maintainer reviewed fix and requested anchor follow-up.
A .NET bug report showed successful NonBacktracking regex matches whose capture groups became empty when the input ended with a newline. The behavior worked in .NET 8 but appeared during an upgrade, and the report included a small reproduction. Stephen Toub assigned the investigation to GitHub Copilot with a suspected earlier change to examine.
Copilot traced the problem to special trailing-newline handling in the input reader. Logic designed for an end anchor was being applied more broadly, producing incorrect transitions and capture tracking. The fix conditioned that handling on whether the relevant end-anchor semantics were present and chose the appropriate reader for capture extraction.
The agent added regression cases across anchor combinations, built the changes and addressed a follow-up concern about strict end-of-input behavior. The PR reports passing functional and unit tests while preserving the existing special end-anchor behavior. Toub reviewed the work, and it merged on October 17, 2025.
The source supports a specific debugging and repair account, not a claim that every regex issue can be delegated.
Prompt
Original prompt
Source: GitHub · Copilot (on behalf of stephentoub)
Frequently asked questions
What made the report reproducible?
It supplied a small NonBacktracking expression and newline-ending input whose match succeeded while the expected capture groups were empty.
What was the root cause?
Special trailing-newline handling intended for particular end-anchor semantics was being applied to other anchored patterns too.
How was neighboring behavior protected?
Copilot added anchor-combination tests, checked existing end-anchor behavior and addressed review concerns before the merged fix.
More details
About this account
GitHub Copilot investigated or implemented the scoped repository task and produced a pull request, with work and checks recorded for maintainer review.
Primary pull request and public API timeline opened and checked on 2026-10-14. PR creation date is the original publication date; merge dates are separate result evidence. Agent-reported test counts; no independent test execution by researcher. Outcomes and test claims are attributed to the source and were not independently reproduced. Original prompt excerpt: reproduced verbatim from the public PR prompt; the full task contains additional context.
Credit: Copilot (on behalf of stephentoub) on GitHub
Source published 11 Oct 2025
Source checked 14 Oct 2026
Tools and topics
GitHub Copilot · .NET Regex · GitHub
Regex debugging · Newline handling · Regression tests
Editorial completeness: 100/100. Measures documented fields, not agent performance or verified outcomes.