obsidian-url-into-selection icon indicating copy to clipboard operation
obsidian-url-into-selection copied to clipboard

Update default fallback regex to be less prone to overtriggering

Open willdhorn opened this issue 3 years ago • 2 comments

I've noticed that the plugin overtriggers a lot when copy and pasting code, which has become more frustrating as I've started to use the Templater and Dataview plugins more.

After playing around with the regex tester on https://regexr.com, I found that the default fallback regex would match many function calls or object references. For example, the fairly straight forward templater expression <% tp.date.now(fmt_month, 0, tp.file.title, fmt_week) %> actually matches twice – once on tp.date.now(fmt_month and a second time on tp.file.title. While the second match is more understandable, as it could technically be a real URL with a weird TLD, I think that a fallback expression should not be prone to overtriggering.

As a less sensitive option, I'm suggesting that ((\w+:\/\/)[-a-zA-Z0-9:@;?&=\/%\+\.\*!'\(\),\$_\{\}\^~\[\]#|]+)` be used at the default fall back regex. In my (albeit brief) testing, I've found this to be much less prone to overtriggering and overall less frustrating to use copy and paste in my notes when working with templates and queries.

willdhorn avatar Feb 19 '22 06:02 willdhorn

Similar issue with different problem / solution suggestion: https://github.com/denolehov/obsidian-url-into-selection/issues/39

GollyTicker avatar May 09 '22 12:05 GollyTicker

I was going to create an issue for this as I'm having trouble with Templater. Have you had good luck with the Regex suggested @willdhorn ?

krlenell avatar Jul 03 '23 06:07 krlenell