Skip to content

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

Johnathon Williams
Johnathon Williams
1 min read

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 urls.map(function(url) {
  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.

automationcodejavscriptzapier

Related Posts

Members Public

Three tips for testing and debugging javascript in Zapier code actions

Zapier is bar none the handiest utility in existence for automating online workflows and connecting different online services. This was true even before the introduction of custom code actions, which allow you to drop in blocks of javascript and python code to manipulate data in your zaps, and it’s

Three tips for testing and debugging javascript in Zapier code actions
Members Public

Should you enable automatic updates in WordPress?

One of the headline features in the recent release of WordPress 5.5 was the ability to enable automatic plugin and theme updates. This follows the inclusion of automatic core updates in WP 3.7. On paper, the arguments for automatic updates are compelling. They’re the fastest and most

Should you enable automatic updates in WordPress?
Members Public

Auto tweet new WordPress posts with categories as hashtags in Zapier

Automatically sending tweets for new posts on your WordPress site is a simple task with Zapier. Recently, though, I wanted to add hashtags for each category assigned to the WordPress post and include that in the tweet as well. Can Zapier accommodate this? Yes, it can, although it turned out

Auto tweet new WordPress posts with categories as hashtags in Zapier