Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
lowell80 opened this issue Nov 26, 2024 · 0 comments

Comments

@lowell80
Copy link

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"\)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant