feat: add shared regex match/replace engine#100
Conversation
Introduce Pattern with literal mode (QuoteMeta) wired into content and rename paths so capture-group replacement can land without changing CLI behavior today. Fixes dolph#37
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 695a0f00cf
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| } | ||
|
|
||
| func (p *Pattern) Replace(s string) string { | ||
| return p.re.ReplaceAllString(s, p.replace) |
There was a problem hiding this comment.
Preserve dollars in literal replacement text
When the CLI still compiles patterns in literal mode, using regexp.ReplaceAllString changes the documented strings.ReplaceAll behavior for replacement strings containing $: values like $1, ${name}, or $$ are expanded/collapsed as regexp replacement syntax instead of being written literally. For example, replacing foo with $HOME in file contents or names will not produce $HOME, so existing invocations that use dollar signs in the replacement corrupt the output despite no regex flag being exposed yet.
Useful? React with 👍 / 👎.
Summary
PatternwithCompile(pattern, replacement, literal)for shared match/replace across content and rename pathsfindReplaceso behavior matches today'sstrings.ReplaceAllsemantics$$escapingMotivation
Foundation for regex mode (#38). Keeps CLI unchanged: patterns stay literal unless
-elands later.Fixes #37
Test plan
go test ./...Made with Cursor