Regex Replace

by bongho
5
4
3
2
1
Score: 35/100

Description

Find and replace text using regular expressions with real-time preview and match highlighting. - This plugin has not been manually reviewed by Obsidian staff.

Reviews

No reviews yet.

Stats

stars
1,567
downloads
0
forks
5
days
NaN
days
NaN
days
0
total PRs
0
open PRs
0
closed PRs
0
merged PRs
0
total issues
0
open issues
0
closed issues
0
commits

Latest Version

Invalid date

Changelog

README file from

Github

Obsidian Regex Replace

A powerful find and replace plugin for Obsidian that supports regular expressions with real-time preview and match highlighting.

Demo License

Features

  • Regular Expression Support: Full JavaScript regex syntax including capture groups ($1, $2, etc.)
  • Real-time Preview: See matches highlighted before replacing
  • Match Highlighting: Visual diff showing before/after changes
  • Regex Flags: Toggle global (g), case-insensitive (i), and multiline (m) flags
  • Selection Mode: Replace only within selected text
  • Pattern History: Save and reuse recent search patterns
  • Pipeline Rulesets: Save reusable multi-step rulesets and apply them in sequence, with a step-by-step preview — and import existing regex-pipeline rulesets
  • Dark/Light Theme: Optimized for both Obsidian themes

Installation

  1. Open Obsidian Settings
  2. Go to Community Plugins and disable Restricted Mode
  3. Click Browse and search for "Regex Replace"
  4. Click Install, then Enable

Manual Installation

  1. Download main.js, manifest.json, and styles.css from the latest release
  2. Create a folder: <YourVault>/.obsidian/plugins/regex-replace/
  3. Copy the downloaded files into this folder
  4. Reload Obsidian and enable the plugin in Settings → Community Plugins

Usage

Opening the Replace Dialog

  • Hotkey: Cmd/Ctrl + Shift + H
  • Command Palette: Cmd/Ctrl + P → "Open Regex Replace"

Interface

┌─────────────────────────────────────────────┐
│ Search Pattern:  [Enter regex pattern]      │
│ Replace With:    [Replacement text]         │
│                                             │
│ Flags: ☑ g (global)  ☐ i  ☐ m              │
│ ☐ Replace in selection only                 │
│                                             │
│ 3 match(es) found                           │
│                                             │
│ Before: Hello [world], hello [world]        │  ← Yellow highlight
│ After:  Hello [WORLD], hello [WORLD]        │  ← Green highlight
│                                             │
│ Matches (3):                                │
│ • "world" → "WORLD"                         │
│                                             │
│                    [Replace All] [Cancel]   │
└─────────────────────────────────────────────┘

Regex Examples

Use Case Search Pattern Replace Result
Find numbers \d+ [NUM] abc123abc[NUM]
Date format (\d{4})-(\d{2})-(\d{2}) $3/$2/$1 2024-12-0808/12/2024
Remove extra spaces \s+ Multiple spaces → single
Wiki to MD link \[\[(.+?)\]\] [$1]($1.md) [[Note]][Note](Note.md)
Header H2 → H3 ^## ### ## Title### Title
Remove bold \*\*(.+?)\*\* $1 **bold**bold
Extract link text \[(.+?)\]\((.+?)\) $1: $2 [text](url)text: url

Flags

Flag Name Description
g Global Replace all matches (not just the first)
i Ignore Case Case-insensitive matching
m Multiline ^ and $ match line starts/ends

Capture Groups

Use parentheses () to capture groups and reference them with $1, $2, etc.:

Search:  (\w+)@(\w+)\.com
Replace: User: $1, Domain: $2

Input:   [email protected]
Output:  User: test, Domain: example

Pipeline Rulesets

A ruleset is a named list of find/replace rules applied in sequence — each rule operates on the previous rule's output. Useful for repeatable, multi-step cleanups (e.g. normalize headers, then collapse whitespace, then fix links).

Defining a ruleset

In Settings → Regex Replace → Pipeline rulesets, click Add ruleset, name it, and write rules using regex-pipeline syntax (one rule per block):

"SEARCH"->"REPLACE"
"\s+"->" "
"##\s"gm->"### "
  • Inline flags follow the search quote (e.g. "foo"gi->"bar"); without them, gm is used.
  • Replacements may span multiple lines.

Applying a ruleset

  • Command Palette: "Apply ruleset (pipeline)" → pick a ruleset → review the step-by-step preview (match count per rule) → Apply pipeline.
  • A rule with an invalid regex is skipped and reported, never aborting the whole run.

Importing from regex-pipeline

Click Import from regex-pipeline to read every ruleset file in <vault>/.obsidian/regex-rulesets/ and convert it into a native ruleset.

Settings

Access via Settings → Regex Replace:

Setting Description Default
Default Flags Pre-selected regex flags g
Show Preview Display before/after preview true
History Limit Max saved patterns 10
Pipeline rulesets Add/edit/delete/import reusable rulesets

Development

# Clone the repository
git clone https://github.com/bongho/obsidian-regex-replace.git

# Install dependencies
npm install

# Build for development (watch mode)
npm run dev

# Build for production
npm run build

# Run tests
npx ts-node --transpile-only test.ts

Changelog

1.1.0

  • Pipeline rulesets: save reusable multi-step rulesets, apply in sequence with step preview
  • Import rulesets from the regex-pipeline plugin
  • New command: "Apply ruleset (pipeline)"

1.0.0

  • Initial release
  • Regex find and replace with preview
  • Real-time match highlighting
  • Pattern history
  • Selection-only mode

License

MIT License - see LICENSE for details.

Contributing

Contributions are welcome! Please feel free to submit a Pull Request.

Support

If you find this plugin useful, consider:

  • Starring the repository on GitHub
  • Reporting issues or suggesting features
  • Contributing code improvements

Made with ❤️ for the Obsidian community