Background: I’m trying to remove the tracking part of a shortened URL by using n8n. For example: A shortened link like abc.dx/aaaa will be revealed through HTTP Request, and will be come abcde.com/aaaaa?utm=trackinglink&ad-goes-here&other-tracking. I want to remove the tracking part using Regex in IF function.
Using an If Node isn’t the way to do what you want but it would let you know if the link contains the tracking code.
If you use the expression editor on any node that you want to use the link in you can remove it there at the time you use it or you could use a set node and set a variable that has the code removed.
and the HTTP request is there to get the page using the same regex option so you can see how you could use it in a normal node.
The actual magic is performed by adding .match(/^[^?]+/) to the end of the input variable, I think where you were going wrong was you thought the If Node sets a variable which is not what an If node or an If statement in programming is for. You would use the If node to see if something matches a certain pattern it doesn’t do any clever extraction you would normally need to handle that after.
Workflow Example
Hopefully this helps and gets you on your way to automating your task
Can you please help in extracting the real URL from this using SET node? All our URLs are coming with Outlook safelinks initial. How can we remove the highlighted part of the URL?
Looking at that if you want the rest of the URL as well you could try using a split on the url= but you have a few URLs there so it might be worth adding an Items List node first and split out URL then add your set node or you could use a code node and do it in a loop.
Can you please share the Javascript to remove the safelinks part of the URL? I tried using ITEM List node but then what should be SET node value?
ITEM List node result