How to use Zapier to extract all URLs from a text source

Here’s a nifty trick for pulling all of the URLs out of text with a Zapier javascript code action.

Using this, you can extract URLs from any Zapier text input. For instance, you could use the Zapier email trigger to pull all of the URLs from an email message, or you could use the push button trigger to pull the URLs from a webpage.

The code is based on Zapier’s example documentation for extracting email addresses from text, combined with this handy regex for extracting URLs.

Here’s the code, which you can paste into a Zapier javascript code action:

var urls = inputData.rawText.match(/\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`!()\[\]{};:'".,<>?«»“”‘’]))/gi) || [];
return {
  return {url: url};

The output will be an array of javascript objects, which you can then process with other Zapier actions. If you’re new to working with code actions in Zapier, check out these tips for testing Zapier code actions and working with arrays.