Skip to content

chore(tools): Report regex capture text in fs_modify_file - #908

Merged
JeanMertz merged 2 commits into
mainfrom
fs-mod-imp
Jul 30, 2026
Merged

chore(tools): Report regex capture text in fs_modify_file#908
JeanMertz merged 2 commits into
mainfrom
fs-mod-imp

Conversation

@JeanMertz

Copy link
Copy Markdown
Collaborator

When a regex pattern applied by fs_modify_file succeeds, the tool now reports the distinct text each match actually bound to, with occurrence counts, most frequent first. This is the one thing a regex author can't otherwise see: the pattern says what was intended and the diff says what resulted, but neither says what the engine bound. A quantifier that runs past its intended boundary (e.g. [a-z-]+ swallowing part of the delimiter-separated text that follows it) now shows up as an unexpected captured string before anyone has to read a diff hunk.

Literal patterns match themselves, so they report nothing new: a lone successful literal pattern still produces an empty report. Multi-pattern and failure reports gain a new section listing what each regex pattern matched, capped at 8 distinct entries per pattern to avoid flooding the output.

Internally, Content::replace_regexp now returns a Replacement carrying the matched strings alongside the new content, and PatternOutcome::Applied carries a matches: Vec<MatchTally> field.

When a regex pattern applied by `fs_modify_file` succeeds, the tool now
reports the distinct text each match actually bound to, with occurrence
counts, most frequent first. This is the one thing a regex author can't
otherwise see: the pattern says what was intended and the diff says what
resulted, but neither says what the engine bound. A quantifier that runs
past its intended boundary (e.g. `[a-z-]+` swallowing part of the
delimiter-separated text that follows it) now shows up as an unexpected
captured string before anyone has to read a diff hunk.

Literal patterns match themselves, so they report nothing new: a lone
successful literal pattern still produces an empty report. Multi-pattern
and failure reports gain a new section listing what each regex pattern
matched, capped at 8 distinct entries per pattern to avoid flooding the
output.

Internally, `Content::replace_regexp` now returns a `Replacement`
carrying the matched strings alongside the new content, and
`PatternOutcome::Applied` carries a `matches: Vec<MatchTally>` field.

Signed-off-by: Jean Mertz <git@jeanmertz.com>
Signed-off-by: Jean Mertz <git@jeanmertz.com>
@JeanMertz
JeanMertz merged commit 56db4dd into main Jul 30, 2026
16 checks passed
@JeanMertz
JeanMertz deleted the fs-mod-imp branch July 30, 2026 11:29
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant