Need help removing :/ or \ in a shortcut using regex to save to Obsidian

I’ve been trying to look at quite a few regex sites with examples, but I remain confused at how I can simply create a regex that will remove a colon, backslash, or slash from the title of a YouTube video title that I’m saving to Obsidian.

Below is the shortcut I’m using, where “OLD_LifeOS” is my vault name and when invoked from the share sheet of a YouTube video, it’s supposed to save the video to a new note in Obsidian.

It turns out that if the title of the video contains a colon, backslash, or slash, Obsidian can’t create the note. If you happen to know other characters that might cause an error and should be removed too, maybe it would be good to remove them as well.

Any help with this would be massively appreciated.

You can use the Replace Text action in Shortcuts to remove the unwanted characters.

You will need to tick the Regular Expression box to make the action work as regex - by default it is a simple replace action. The items to be removed are enclosed in [square brackets]. As the colon and backslash are special characters, they need escaping which is done by placing a backslash before the character in the pattern match. In the pattern in the image above, the first backslash is an escape for the second backslash and the second backslash also acts as the escape character for the colon.

I have left the second variable in the Replace action blank (it shows the word World in light text) to just remove the matched characters. You could replace the characters with an underscore or similar if required by entering the character in that field.

Hope this makes sense and helps.

1 Like

Thank you. That explanation makes a ton more sense than I was finding other places. Because it was removing stuff, not matching it, and because they are special characters, not letters or numbers, I wasn’t getting it.

I really appreciate the help. I look forward to applying it and getting stuff saved to Obsidian.

1 Like

FWIW, I’m finding ChatGPT very helpful for these kinds of questions.

Or even more explicitly:

But sometimes ChatGPT gives answers with confidence that sound correct but that actually aren’t. Sometimes I have to say “That didn’t work. What happened was [x]” and it says “Oh sorry, try this instead” and then it works. Other times it just points me in the right direction and I can figure it out from there. Your mileage may vary.