Convert Multiple URL's to MD Image Links

A short macro I use to convert URL's into Markdown image links. This macro leverages Keyboard Maestro's Regular Expression matching in the Search and Replace action.

I've blatantly stolen John Gruber's regular expression for matching URL's which is the best I've tried.

A tiny feature of Keyboard Maestro that I rarely (if ever) see used is the regular expression matching and the regex replacement token in the search and replace actions. It's a fairly powerful way to do on-the-fly text conversion. It follows the standard regular expression back reference syntax1 where "$1" is the first match.

Here's the macro:

Here's the gorgeous Gruber regex:

(?i)\b((?:[a-z][\w-]+:(?:/{1,3}|[a-z0-9%])|www\d{0,3}[.]|[a-z0-9.\-]+[.][a-z]{2,4}/)(?:[^\s()<>]+|\(([^\s()<>]+|(\([^\s()<>]+\)))*\))+(?:\(([^\s()<>]+|(\([^\s()<>]+\)))*\)|[^\s`!()\[\]{};:'".,<>?«»“”‘’]))

I can grab any text that contains URL's and instantly convert them to image links, while leaving all other text in place. For example, this block of text:

Is converted to this block:


  1. I'm way out of my depth with regex. I'm probably talking bollocks. Hey, what's new?