Writing Regex Replacer

approved

by Jakob Lien

Replaces your text as you write, using configurable regexes. - This plugin has not been manually reviewed by Obsidian staff.

22 downloadsUpdated 3d agoMIT

Writing Regex Replacer

Replaces your text as you write, using configurable regexes.

An obvious use case for this is to expand for example a Jira issue into a link to that issue. The regex need to replace PROJ-123 with [PROJ-123](https://organisation.atlassian.net/browse/PROJ-123) is just:

  • source: PROJ-\d+
  • target: [$0](https://organisation.atlassian.net/browse/$0)

The actual matching and replacing is done using Javascripts replace method on your current line, but a few convenience features are added to make it easier to use.

  • For each pattern (the set of source and target regex), there are two toggles, both of which have tooltips on them:
    1. Whether or not the match needs to have whitespace before it. In the Jira example above, this avoid matching ABCPROJ-123
    2. Whether or not to require a space after the regex before matching. In the Jira example above, this avoids matching and replacing PROJ-1 before you type the second two digits.
  • Javascript replace apparently doesn't support $0 to reference the entire match directly, so the plugin automatically replaces $0 with what javascript does support, $&.

The plugin only replaces as you type, and only on the current line.

For plugin developers

Search results and similarity scores are powered by semantic analysis of your plugin's README. If your plugin isn't appearing for searches you'd expect, try updating your README to clearly describe your plugin's purpose, features, and use cases.