Convert Zotero tag to Obsidian tag?

Hi there,

I am having some trouble getting a macro using regex to work properly and I am stuck.

I would like the macro to take a tag (to be renamed) from Zotero and (1) convert - (note the sp) to / (no sp), (2) replace all remaining spaces with _ and (3) put all the text in lower case.

This is my macro so far:

convert zotero tag to Obsidian tag.kmmacros (6.5 KB)

If I use it on the following tag 'Definition of- public interest' and I get 'definition_of-_public_interest'. So it achieves (2) and (3) but not (1) - even though I have (1) first.

Any suggestions would be much appreciated!

Just remove the backslash from before the dash.

And if you want to test this sort of thing, create an action like this, and look at the bottom of the action. The first action is the one that works, the second action is the one that doesn't work, for the same reason yours doesn't work, I believe.

P.S. I should have used "Regular Expression" instead of "String", but the result is the same, because BACKSLASH-DASH is not a regular expression.

1 Like

Thanks @Airy! That worked. I had to keep with the regex in order to delete the space after the hypen but I removed the \ from before the dash and it is working correctly.

Thanks for your help

Careful! That's not what you are doing -- you're searching for "dash followed by any character". So a- b becomes a/b, as you want, but a-b becomes a/, which you probably don't.

"Normal" text replacement should work here, and it'll be more obvious in the KM actions if you use the %Space% token rather than a literal space.

Unless you're using the converted text elsewhere later there's no need to use a named clipboard -- it's ever-so slightly more efficient to do everything on the System clipboard.

1 Like

Excellent catch. As soon as he said, "That's working" I probably tuned out.

1 Like