Skip to content

[FR] Is there a way to use regex modifier (such as "i" - case insensitive) for a Custom Replacement?  #107

Open
@lowell80

Description

@lowell80

Feature Description

I'd like to create a custom replacement that fixes up unnecessarily complicated URLs that seem to primarily come from copying text into Obsidian from MS office tools.

I'm not as familiar with Javascript's Regex dialect, but apparently it's only possible to use regex modifiers within a specific portion of an expression. So where as with PCRE or Python I could just use (?i)term at the front of the regex, with Javascript it seems like you have to use (?i:term). At least according to this mdm doc.

Example

I'd like to use an a custom replacement configuration like this:

Find: \[([^\]]+)\]\((\S+) "(?i:\2)"\)
Replace: [$1]($2)

The goal is to remove the redundant, and for some reason (lower case), quoted URL text as it just get's ugly and long when dealing with URLs of any significant length. (Sharepoint links are obnoxious, for example)

Input:

[Example][https://example.com/PATH "https://example.com/path"]

Result:

[Example][https://example.com/PATH]

FYI. I'm not 100% sure that the syntax is correct for JavaScript. Regex101 doesn't seem to like, but I'm not sure why. The easy answer would be to pass modifiers directly to the RegeEx() constructor, but that would require another input field. For whatever it's worth, I got this working with PCRE2 when written as: (?i)\[([^\]]+)\]\((\S+) "\2"\)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions