Find and delete action

Hi, in my workflow I always want to find some texts like this %%xxxx%% ( some extra texts were wrapped by %%), and delete them.
If I want to make an action to find them all and delete all of them in one article. ( %%xxx%%, include percent sign. Is there any tutorial articles for this action or what syntaxes should I learn?

Many thanks for your help! Keep safe.

1 Like

JavaScript and regular expressions.

It isn’t clear whether you are trying to remove the “%%xxxx%%” to leave nothing, or the to leave “xxxx”, so I put together a couple of options for you to take a look at. I’ve tried them both in actions using script steps and they look to work as expected.

Remove Placeholder

draft.content = draft.content.replaceAll(/\%\%.*?\%\%/g, "");
draft.update()

This matches all characters (lazily) between two pairs of percentage symbols and replaces them with nothing.

Remore Delimiters

draft.content = draft.content.replaceAll(/\%\%(.*?)\%\%/g, "$1");
draft.update()

This matches all characters (lazily) between two pairs of percentage symbols and replaces them with the content that was found between the percentage symbols.

For the difference between the two, note that the second one uses parentheses in the first parameter of the replaceAll() function to set-up a group in the regular expression match, and this is then referenced in the replacement with the $1

Hope that helps.

Wow. Really thanks for your magic and i just want to remove all of them including text between %%.

Actually this action works with Obsidian. I use readwise community plugin to pull my readwise notes into my vault, after the plugin download the notes it will include something likes this “%% highlight_id: 199756183 %%”. I want to remove them and reorganize them.

Hope this will be helpful for those who have same needs.

About the JS, I think I still need to gather more momentum to begin to learn. It is far beyond me to reach.