Extracting clipboard contents to create a custom snippet?

Hi! I was wondering if it's possible to use TextBlaze commands to paste a custom Markdown link, such as this:

[Habitica Wiki](https://habitica.fandom.com/wiki/Habitica_Wiki)

Basically what I would want to do is copy a URL (e.g. https://habitica.fandom.com/wiki/Habitica_Wiki) and then use a TextBlaze shortcut to paste the above Markdown in its entirety. I know there is a clipboard command, but is there a way to also extract the last part of the URL (e.g. "Habitica_Wiki"), remove the underscore, and put that in brackets before the URL?


You could do something like the following

If you have copied a valid URL to your Clipboard, this will work (you need to reload the page after making a copy for this demo to update):

[{=replace(extractregex({clipboard}, ".*/(.+?)$"), "_", " ")}]({clipboard})

If you didn't copy a valid url, here is an example of the above working with a dummy clipboard data:

[{=replace(extractregex(dummy_clipboard, ".*/(.+?)$"), "_", " ")}]({=dummy_clipboard})

The key item here is the formula command {=}. Text Blaze formulas let you do data manipulation like in Excel. You can learn more here:

The extractregex() function in a formula allows you to grab a specific part of what's in the clipboard. For example, the ".*/(.+?)$" regular expression here means: "get everything after the last '/' to the end of the clipboard". We then use the replace() function to replace all occurrences of underscores with spaces.

1 Like

Thank you so much! I didn't realize TextBlaze had that much power! Pretty amazing!

(P.S. I also really love how we get a live preview of our posts before we have to submit them!)

Hmm, okay one further question. This probably just has to do with the regular expression itself, but I'm not so great at writing those!

Let's say I have a link like this:


So now the last part has a subsection, found after the "#" symbol. How can I extract just that part, without the "Backgrounds" part being included?


Something like this should work: ".*(?:/|#)(.+?)$". We changed the "/" to a "(?:/|#)". "(/|#)" means match a "/" or a "#". The "?:" in front of it means this isn't the group we want to extract from the function.

[{=replace(extractregex(dummy_clipboard, ".*(?:/|#)(.+?)$"), "_", " ")}]({=dummy_clipboard})

1 Like

Thank you so much! Sorry it took so long to reply. I never got a notice that you had responded, and I just thought to check tonight!

That was very helpful! Thank you again!