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.
この拡張機能は、複数の正規表現ルールを作成・管理し、現在アクティブなエディタに対して一括置換を実行できるツールです。主な特徴は以下の通りです。
- サイドバー内の専用 UI でルールの追加・編集・削除・並べ替えが可能。
- ライブプレビュー: 検索入力中にアクティブなエディタ内のマッチ箇所をハイライトします(プレビューは入力のバリデーションを行い、無効な正規表現はインラインでエラーメッセージを表示します)。
- ルールごとの有効/無効切替(チェックボックス)により、一時的にルールを無効化できます。無効なルールはハイライト・置換処理の対象外になります。
- 置換実行は保存されたルールを上から順に現在のファイルに適用します。
注意: 以前にあった「ルールセットの保存/インポート/エクスポート」機能は撤回されています(実装されていません)。
- 左のアクティビティバーで「一括置換ルール」ビューを開く。
検索 (正規表現)と置換に入力し、「ルールを追加」を押す。- ルールがリストに追加され、エディタ上でマッチ箇所がハイライトされる。
- ルールを無効化したい場合、リストのチェックボックスをオフにする。
- 「現在のエディタで置換を実行」ボタンで置換を適用。
コマンドパレットから利用可能なコマンド:
batch-regex-replace.execute— 現在のエディタに対して全ルールを適用します。
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.
- 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.executeto perform the replacements.
batch-regex-replace.execute— Apply all rules to the active editor.
- The extension stores rules in the extension global state. Rules include:
find(pattern),replace(string),flags(RegExp flags), andenabled(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.
MIT
- 検索パターンはプレーンな正規表現文字列、または
/pattern/flagsの形式で入力できます。例:/foo/iや\bword\b。 - プレビューでは自動的に global フラグ (
g) が付与されて全マッチをハイライトします。ルール保存時はflagsを保存して実行時にも使用します。 - 置換の適用は現在の実装では「上から順にルールを適用」します。あるルールによる置換が次のルールのマッチ対象に影響する点に注意してください。
- 無効な正規表現が入力された
- サイドバーにインラインでエラーメッセージが表示され、プレビューと保存は行われません。正規表現の構文を確認してください。
- 大きなファイルでプレビューが遅い/負荷が高い
- プレビューはデバウンスされていますが、非常に大きなファイルや複雑な正規表現では処理に時間がかかります。必要ならデバウンス間隔を長くするか、プレビューをオフにするオプションを検討してください。
- 期待通りに置換されない(順序の問題)
- ルールは上から順に適用されます。置換の相互作用がある場合はルールの並び替えを調整してください。
- Invalid regular expression
- 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.
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 testNotes for contributors:
- Code lives in
src/and compiles toout/. - 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.