ashlr

ashlr__search_replace_regex

Regex-based search and replace across multiple files. Returns a diff summary and match count — not the full file contents.

ashlr__search_replace_regex applies a regex search-and-replace across one or more files and returns a compact diff summary (changed lines only). Use it for bulk renames or pattern-based transforms that span multiple files when ashlr__edit_structural doesn't apply (non-TS/JS files, or regex logic that can't be expressed as a symbol rename).

Parameters

ParameterTypeRequiredDescription
patternstringyesRegex pattern to search for (ECMAScript regex syntax).
replacementstringyesReplacement string (supports $1, $2 capture group refs).
pathsstring[]yesList of file paths or glob patterns to apply the replace to.
flagsstringnoRegex flags (default: g). Add i for case-insensitive.

Example

{
  "tool": "ashlr__search_replace_regex",
  "arguments": {
    "pattern": "console\\.log\\(",
    "replacement": "logger.debug(",
    "paths": ["src/**/*.ts"],
    "flags": "g"
  }
}

Returns

A compact diff summary:

Replaced 14 occurrences across 6 files:
  src/auth/handler.ts        3 replacements
  src/auth/middleware.ts     2 replacements
  ...

When to use ashlr__edit_structural instead

For TypeScript/TSX/JS/JSX symbol renames (functions, classes, variables), prefer ashlr__edit_structural — it is scope-aware and won't rename occurrences that shadow the target symbol.

Typical savings

−80% vs ashlr__multi_edit with N edits — one call covers all files, and only match counts + diff lines are returned.

On this page