Parse string to get a link

Hi, i'm trying to get a link inside the payload of the Twitter node : "Tonga : Animation satellite qui montre l'explosion suivie d'un important panache de fumée qui s'est élevée dans l'atmosphère suite à l'éruption du volcan Hunga Tonga-Hunga-Ha'apai et qui a déclenché une alerte tsunami. https://twitter.com/RebeccaRambar/status/1482360722105511946/video/1"

But i don't know how to do that for all the tweets i receive.
Thx.

Hello .. you can use the power of Regular Expressions in a Function node to filter from your string any link
In the example below an array is produced with all matching links

Example Flow:

[{"id":"53816c0d1d6d081a","type":"inject","z":"54efb553244c241f","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"","payloadType":"date","x":270,"y":1020,"wires":[["0eae0d0c48f8a13d"]]},{"id":"2bf55b03434e0438","type":"function","z":"54efb553244c241f","name":"","func":"msg.payload = msg.payload.match(/http[s]?:\\/\\/[^\\s]+/g)\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":620,"y":1020,"wires":[["8df9347709fc5181"]]},{"id":"8df9347709fc5181","type":"debug","z":"54efb553244c241f","name":"2","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","statusVal":"","statusType":"auto","x":770,"y":1020,"wires":[]},{"id":"0eae0d0c48f8a13d","type":"template","z":"54efb553244c241f","name":"data","field":"payload","fieldType":"msg","format":"text","syntax":"plain","template":"Tonga : Animation satellite qui montre l'explosion suivie d'un important panache de fumée qui s'est élevée dans l'atmosphère suite à l'éruption du volcan Hunga Tonga-Hunga-Ha'apai et qui a déclenché une alerte tsunami. https://twitter.com/RebeccaRambar/status/1482360722105511946/video/1\nTonga : https://twitter.com/RebeccaRambar/status/43534534/video/2 Animation satellite qui montre l'explosion suivie d'un important panache de fumée qui s'est élevée dans l'atmosphère suite à l'éruption du volcan Hunga Tonga-Hunga-Ha'apai et qui a déclenché une alerte tsunami. ","output":"str","x":430,"y":1020,"wires":[["2bf55b03434e0438","4a70e2267055ff0e"]]},{"id":"4a70e2267055ff0e","type":"debug","z":"54efb553244c241f","name":"1","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","statusVal":"","statusType":"auto","x":510,"y":940,"wires":[]}]

Possibly something like this in a function node:

let regex = '(http|https|ftp|ftps)\:\/\/[a-zA-Z0-9\-\.]+\.[a-zA-Z]{2,3}(\/\S*)?';
let index = msg.payload.search(regex); 
let payload = msg.payload.substring(index);
msg.payload = payload.split(' ')[0];    // Drop anything from a space character after URL
return msg;

You will probably want to filter out tweets which don't include a URL (index == -1)

Edit - Snap - almost!

Thx ! I'm going to try it.

This topic was automatically closed 60 days after the last reply. New replies are no longer allowed.