Skip to content

feat: add shared regex match/replace engine#100

Open
leno23 wants to merge 1 commit into
dolph:mainfrom
leno23:feat/regex-engine-issue-37-v2
Open

feat: add shared regex match/replace engine#100
leno23 wants to merge 1 commit into
dolph:mainfrom
leno23:feat/regex-engine-issue-37-v2

Conversation

@leno23
Copy link
Copy Markdown

@leno23 leno23 commented May 31, 2026

Summary

  • Introduce Pattern with Compile(pattern, replacement, literal) for shared match/replace across content and rename paths
  • Wire literal mode (default) through findReplace so behavior matches today's strings.ReplaceAll semantics
  • Add unit tests for literal equivalence, capture groups, named groups, and $$ escaping

Motivation

Foundation for regex mode (#38). Keeps CLI unchanged: patterns stay literal unless -e lands later.

Fixes #37

Test plan

  • go test ./...
  • Benchmarks show literal path works (regex overhead noted for follow-up)

Made with Cursor

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
Copy link
Copy Markdown

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 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".

Comment thread pattern.go
}

func (p *Pattern) Replace(s string) string {
return p.re.ReplaceAllString(s, p.replace)
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge 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 👍 / 👎.

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.

Build regex engine with capture-group replacement support

1 participant