Introduction
Obsidian users, rejoice! The “Regex Replace” plugin is here to revolutionize how you manipulate text within your notes. This powerful tool brings regex-based search and replace capabilities directly into your Obsidian editor, making complex text transformations simple and efficient. With an intuitive modal dialog, real-time match preview, and a robust preset system, “Regex Replace” is an indispensable addition to any Obsidian workflow.

Key Features for Seamless Text Editing
This plugin is packed with features designed for precision and ease of use:

  1. Regex Input Fields:
    • Regex Pattern: Define your search criteria using standard JavaScript regex syntax.
    • Replacement Text: Specify the string to replace matches, supporting $1, $2 for capturing groups.
    • Flags: Control your search behavior with flags like g (global), i (case-insensitive), and m (multiline).
  2. Flexible Options:
    • Use only selection: Limit replacements to currently selected text for focused editing.
    • Replace all: Toggle between replacing all occurrences or just the first match.
  3. Live Preview:
    • Witness your changes instantly with a scrollable table displaying up to 50 matches.
    • Each row clearly shows the line “before” and “after” the replacement, with matches highlighted for context.
  4. Execute:
    • Apply your regex transformation to either the selected text or the entire document with a single click, instantly updating your editor.

Effortless Installation
Getting “Regex Replace” up and running is straightforward:

  1. Download the plugin files: manifest.json and main.js.
  2. Place these files into a new folder within your Obsidian vault, typically:
    <your-vault>/.obsidian/plugins/regex-replace/
    Ensure the folder contains both manifest.json and main.js.
  3. Restart or reload your Obsidian application.
  4. Navigate to Settings → Community Plugins and enable “Regex Replace.”

How to Use the Plugin
Accessing the “Regex Search & Replace Modal” is simple:

  • Command Palette: Press Ctrl+P (or Cmd+P) and search for “Regex Search & Replace.”
  • Right-click Context Menu: Right-click inside the editor and select “Regex Search & Replace.”

Streamline Your Workflow with Presets
Presets allow you to save, organize, and quickly reuse your most frequent regex operations:

  • Saving a Preset: Configure your desired pattern, replacement, and options, then click “Save as preset.” Give it a name, and it will appear in your dropdown list. Existing presets with the same name will be overwritten.
  • Loading a Preset: Select a preset from the dropdown menu, and all fields will automatically populate with its saved values, ready for preview and execution.
  • Deleting a Preset: Choose the preset you wish to remove from the dropdown, then click “Delete preset” to permanently erase it.

Practical Examples

Example 1: Swap First and Last Names
* Original Text:
Wisniewski Frank
Adenau
Wisniewski Frank
Adenau

* Search Pattern: ^(\w+) (\w+)\\n^(\w+)
* Replacement Text: $2, $1, 53518 $3
* Result:
Frank, Wisniewski, 53518 Adenau
Frank, Wisniewski, 53518 Adenau

Example 2: Replace All ‘i’ with ‘x’
* Original Text:
This is a simple line
With multiple words

* Search Pattern: i
* Replacement Text: x
* Result:
Thxs xs a sxmple lxne
Wxth multxple words

Tips for Mastering Regex Replace

  • Utilize ^ and $ for line-start and line-end anchors.
  • Employ capturing groups ( ... ) and refer to them with $1, $2, etc., in your replacement string.
  • Combine flags for advanced control: g (global), i (case-insensitive), m (multiline).

Known Limitations

  • Previews for very large documents with numerous matches may experience some slowdown (capped at 50 matches for performance).
  • The plugin adheres to JavaScript\’s RegExp engine, so advanced features from other regex engines (like PCRE) may not be supported.

About the Author
“Regex Replace” was developed by Frank Wisniewski as a simple yet powerful plugin for Obsidian.

Leave a Reply

Your email address will not be published. Required fields are marked *

Fill out this field
Fill out this field
Please enter a valid email address.
You need to agree with the terms to proceed