This Visual Studio Code extension provides a compact sidebar UI to manage multiple regex-based search-and-replace rules and apply them to the active editor.
This extension provides a sidebar UI to manage regex search-and-replace rules and apply them to the active editor.
Key features:
Add / edit / delete / reorder rules in the sidebar.
Live preview: while typing a search pattern, matches in the active editor are highlighted. Invalid regex input is detected and an inline error message is shown in the sidebar preview area.
Per-rule enable/disable toggle (checkbox). Disabled rules are ignored by both highlighting and execution.
Apply all saved rules to the active file in order with a single command.
Note: The previous idea to provide named rule set save/load/import/export has been removed and is not available in this version.
Quick usage
Open the "Regex Replace" view from the activity bar.
Enter the search (regex) and replacement strings and click "Add Rule".
Observe highlighted matches in the active editor while typing.
Toggle a rule off to temporarily exclude it from preview and execution.
Use the "Apply to current editor" button or run batch-regex-replace.execute to perform the replacements.
Command
batch-regex-replace.execute — Apply all rules to the active editor.
Development / Notes
The extension stores rules in the extension global state. Rules include: find (pattern), replace (string), flags (RegExp flags), and enabled (boolean).
Live preview is implemented via messages from the webview to the extension which validates the regex and updates decorations in the active editor.
If you want re-introduce export/import or named sets, we can add a safe implementation that either downloads JSON from the webview or uses VS Code's save dialog.
If the search input is not a valid RegExp, an inline message appears in the sidebar and preview/save will be blocked. Fix the regex syntax.
Preview is slow on very large files
Preview is debounced but may still be expensive for very large files or complex patterns. Consider increasing the debounce timeout or disabling live preview for such files.
Replacements not matching expectations (order effects)
Rules are applied in order. If one rule affects the text that later rules match, adjust the rule order accordingly.
Developer guide / Build & Debug
Quick steps to build and run locally:
Install dependencies:
npm install
Compile TypeScript:
npm run compile
Run the extension in the Extension Development Host (press F5 in VS Code).
Tests (if present) can be run with:
npm test
Notes for contributors:
Code lives in src/ and compiles to out/.
Webview assets are in media/.
Keep the webview messages and their handlers in sync when modifying the UI.
If you'd like, I can also add screenshots, a quick GIF demonstrating live preview + toggle, and a short examples section showing typical regex patterns and expected replacement results.