MahmoudFawzyKhalil / obsidian-global-search-and-replace

A plugin to do a global search and replace in all your Obsidian vault files.
GNU Affero General Public License v3.0
84 stars 4 forks source link

Replace with regex #13

Closed edgar-505 closed 5 months ago

edgar-505 commented 1 year ago

hi I'm trying to replace an array of numbers:

19:22 19:23 19:24 19:25 19:26

then I searched them using the regex : 19:(22|23|24|25|26) but I can't add anything around the numbers with regex , I've been trying to put all of them inside a square bracket like : [19:26] using [$&] please also allow to replace with regex.

figma has have a pretty good example for renaming things with regex.

nicolnt commented 1 year ago

VS Code regex replace allows working with groups also. Here's an example:

Search pattern

/(19):(\d\d)

Replace

hour: $1, min: $2 

Result

hour: 19, min: 22
hour: 19, min: 23
hour: 19, min: 24
hour: 19, min: 25
hour: 19, min: 26
voltel commented 1 year ago

Now, I understand that Obsidian uses a Javascript flavour of regular expressions. But as nicolnt mentioned above, referencing captured groups in the replacement string (e.g., "$1") is very much welcome.