well only if you are running a regex and only then if you select the option to return all matches.
It's not as elegant? But yes, moving the JSONata change node before the switch node would be a fix - just as many nodes and just as much dryness, i.e. the regexp is only defined once in the change node. But the problem might come if there are more that one being checked - if I have three different URLs that I want to check against then the change node would get more complex.
I.e. imagine the switch node in these example having 3 different reg exps and if one matches, then you have the parts already. Using a change node (if using function node then this isn't relevant - you'd do it all in one function node but I want to explicitly avoid that solution), you would have to set three variables on the message, one per regexp. Then you have to check all three in the switch node which isn't possible since you can only take one parameter to check against.
So then you can add Jsonata to the switch node and add expressions as switch cases ....
[{"id":"a1e53a1885410b42","type":"group","z":"f93e13e54f881a08","name":"change before switch","style":{"label":true},"nodes":["60127078a554cd5d","409075af1cceac6a"],"x":684,"y":55.5,"w":376,"h":157.5},{"id":"60127078a554cd5d","type":"switch","z":"f93e13e54f881a08","g":"a1e53a1885410b42","name":"","property":"truevalue","propertyType":"msg","rules":[{"t":"eq","v":"$$.param1","vt":"jsonata"},{"t":"eq","v":"$$.param2","vt":"jsonata"},{"t":"eq","v":"$$.param3","vt":"jsonata"}],"checkall":"true","repair":false,"outputs":3,"x":984,"y":104,"wires":[[],[],[]]},{"id":"409075af1cceac6a","type":"change","z":"f93e13e54f881a08","g":"a1e53a1885410b42","name":"","rules":[{"t":"set","p":"param1","pt":"msg","to":"$match($$.value, /one/)","tot":"jsonata"},{"t":"set","p":"param2","pt":"msg","to":"$match($$.value,/two/)","tot":"jsonata"},{"t":"set","p":"param3","pt":"msg","to":"$match($$.value,/three/)","tot":"jsonata"}],"action":"","property":"","from":"","to":"","reg":false,"x":790,"y":172,"wires":[["60127078a554cd5d"]]},{"id":"a9865a3281e9ba64","type":"group","z":"f93e13e54f881a08","name":"change after","style":{"label":true},"nodes":["5c97f9ac25f0fd86","855ee9069bf02b99","2dcd693abb5eb6c4","e99ae3c6f43f1a57"],"x":926,"y":232,"w":476,"h":174},{"id":"5c97f9ac25f0fd86","type":"switch","z":"f93e13e54f881a08","g":"a9865a3281e9ba64","name":"","property":"value","propertyType":"msg","rules":[{"t":"regex","v":"/one/","vt":"str","case":false},{"t":"regex","v":"/two/","vt":"str","case":false},{"t":"regex","v":"/three/","vt":"str","case":false}],"checkall":"true","repair":false,"outputs":3,"x":1002,"y":333,"wires":[["855ee9069bf02b99"],["2dcd693abb5eb6c4"],["e99ae3c6f43f1a57"]]},{"id":"855ee9069bf02b99","type":"change","z":"f93e13e54f881a08","g":"a9865a3281e9ba64","name":"","rules":[{"t":"set","p":"payload","pt":"msg","to":"$match($$.value, /one/)","tot":"jsonata"}],"action":"","property":"","from":"","to":"","reg":false,"x":1187,"y":273,"wires":[[]]},{"id":"2dcd693abb5eb6c4","type":"change","z":"f93e13e54f881a08","g":"a9865a3281e9ba64","name":"","rules":[{"t":"set","p":"payload","pt":"msg","to":"$match($$.value, /two/)","tot":"jsonata"}],"action":"","property":"","from":"","to":"","reg":false,"x":1230,"y":317,"wires":[[]]},{"id":"e99ae3c6f43f1a57","type":"change","z":"f93e13e54f881a08","g":"a9865a3281e9ba64","name":"","rules":[{"t":"set","p":"payload","pt":"msg","to":"$match($$.value, /three/)","tot":"jsonata"}],"action":"","property":"","from":"","to":"","reg":false,"x":1296,"y":365,"wires":[[]]}]
so with this change, you won't need to do the change before hand and the change afterwards won't be necessary either, you would just have a single switch node.
I can't speak for Nick - but at the time I was also unaware of Yahoo Pipes - I was an old hardware engineer used to designing logic with gates and flow diagrams and using this new fangled MQTT thing and wanting to manipulate topics, and Nick had written loads of MQTT libraries, and had an interest in web design and diagramming and funky libraries like D3.
So logically timeline wise you are correct but how much influence one had on another is hard to say. Obviously people pointed out the similarity at the time and we were like yeah - good validation !
something like
but what I don't like is that the space for entering the regex is somewhat small and hard to see what is going on - hard to edit and debug - and almost by definition when you start using groups the regex will get large quickly.
:wide-eyed-stare: - hand waving, revising, ... hm never let the truth get in the way of wheel re-invention ![]()
That's quite amazing to think that Node-RED was created from a completely different purpose yet came to the same place that Yahoo! Pipes - for example - was for RSS feeds. It just shows that data will be data and it flows in the same ways!
And hence the lines are called "wires" when they should really be called "pipes" - wires always have a value, while pipes only have a value when the water ... data ... flows.
It's one those things that helped me to understand why there is only one input to a node ... else you have to synchronise somehow, i.e. when do two inputs arrive at the same time?
With wires this wouldn't be a problem since you'd be using a clock to sample at a frequency - much as noisecraft does.
EDIT: not meaning to be rude here - sorry if it came across like that. Wires/pipes .. a rose by any other name ![]()
Wowowo Whoop! :wide-eyed-stare-again: ![]()
Thanks for doing that, looking really cool!
Something like JSONata editor and ellipse but for regular expressions ... which then opens the can of worms of - perhaps - creating a reg expression editor akin to the jsonata editor....
It would probably find a lot of interest if something like https://regex101.com/ or reg-visualizer - Visual Studio Marketplace was integrated into NR!
I would probably change the param output to an object, and layout flow slightly differently
e.g
[{"id":"d132b44c0fbbc9b0","type":"inject","z":"613df62afc8a16bf","name":"","props":[{"p":"value","v":"/one/two/three","vt":"str"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","x":190,"y":800,"wires":[["b5fd14a103ede083"]]},{"id":"b5fd14a103ede083","type":"change","z":"613df62afc8a16bf","name":"","rules":[{"t":"set","p":"param.one","pt":"msg","to":"$match($$.value, /one/)","tot":"jsonata"},{"t":"set","p":"param.two","pt":"msg","to":"$match($$.value,/two/)","tot":"jsonata"},{"t":"set","p":"param.three","pt":"msg","to":"$match($$.value,/three/)","tot":"jsonata"}],"action":"","property":"","from":"","to":"","reg":false,"x":380,"y":840,"wires":[["80ea0d4984239a20","d21a33a493a1406a"]]},{"id":"805a9f28d8799436","type":"inject","z":"613df62afc8a16bf","name":"","props":[{"p":"value","v":"/one/four/three","vt":"str"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","x":190,"y":840,"wires":[["b5fd14a103ede083"]]},{"id":"80ea0d4984239a20","type":"debug","z":"613df62afc8a16bf","name":"debug 2591","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","statusVal":"","statusType":"auto","x":590,"y":920,"wires":[]},{"id":"d21a33a493a1406a","type":"switch","z":"613df62afc8a16bf","name":"","property":"param","propertyType":"msg","rules":[{"t":"hask","v":"one","vt":"str"},{"t":"hask","v":"two","vt":"str"},{"t":"hask","v":"three","vt":"str"}],"checkall":"true","repair":false,"outputs":3,"x":590,"y":820,"wires":[["405608c05c819b79"],["d900e2471399209b"],["a3b3ddf8b955c9d0"]]},{"id":"405608c05c819b79","type":"change","z":"613df62afc8a16bf","name":"","rules":[{"t":"set","p":"payload","pt":"msg","to":"$match($$.value, /one/)","tot":"jsonata"}],"action":"","property":"","from":"","to":"","reg":false,"x":760,"y":760,"wires":[["381d5a8fd9ee1399"]]},{"id":"d900e2471399209b","type":"change","z":"613df62afc8a16bf","name":"","rules":[{"t":"set","p":"payload","pt":"msg","to":"$match($$.value, /two/)","tot":"jsonata"}],"action":"","property":"","from":"","to":"","reg":false,"x":760,"y":800,"wires":[["4e20f5f2b9683c7f"]]},{"id":"a3b3ddf8b955c9d0","type":"change","z":"613df62afc8a16bf","name":"","rules":[{"t":"set","p":"payload","pt":"msg","to":"$match($$.value, /three/)","tot":"jsonata"}],"action":"","property":"","from":"","to":"","reg":false,"x":760,"y":840,"wires":[["29a3dd89320f068c"]]},{"id":"381d5a8fd9ee1399","type":"debug","z":"613df62afc8a16bf","name":"one","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","statusVal":"","statusType":"auto","x":930,"y":760,"wires":[]},{"id":"4e20f5f2b9683c7f","type":"debug","z":"613df62afc8a16bf","name":"two","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","statusVal":"","statusType":"auto","x":930,"y":800,"wires":[]},{"id":"29a3dd89320f068c","type":"debug","z":"613df62afc8a16bf","name":"three","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","statusVal":"","statusType":"auto","x":930,"y":840,"wires":[]}]
Ah, yes - that would do it. The "set msg.payload" change nodes after the switch won't be strictly necessary but yes that would the simplest solution today.
Visually though, what is more understandable:
[{"id":"d132b44c0fbbc9b0","type":"inject","z":"f93e13e54f881a08","name":"start here","props":[{"p":"value","v":"/one/two/three","vt":"str"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","x":781,"y":195,"wires":[["b5fd14a103ede083"]]},{"id":"b5fd14a103ede083","type":"change","z":"f93e13e54f881a08","name":"","rules":[{"t":"set","p":"param.one","pt":"msg","to":"$match($$.value, /one/)","tot":"jsonata"},{"t":"set","p":"param.two","pt":"msg","to":"$match($$.value,/two/)","tot":"jsonata"},{"t":"set","p":"param.three","pt":"msg","to":"$match($$.value,/three/)","tot":"jsonata"}],"action":"","property":"","from":"","to":"","reg":false,"x":986,"y":195,"wires":[["d21a33a493a1406a"]]},{"id":"d21a33a493a1406a","type":"switch","z":"f93e13e54f881a08","name":"","property":"param","propertyType":"msg","rules":[{"t":"hask","v":"one","vt":"str"},{"t":"hask","v":"two","vt":"str"},{"t":"hask","v":"three","vt":"str"}],"checkall":"true","repair":false,"outputs":3,"x":1215,"y":195,"wires":[["381d5a8fd9ee1399"],["4e20f5f2b9683c7f"],["29a3dd89320f068c"]]},{"id":"381d5a8fd9ee1399","type":"debug","z":"f93e13e54f881a08","name":"one","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","statusVal":"","statusType":"auto","x":1418,"y":160,"wires":[]},{"id":"4e20f5f2b9683c7f","type":"debug","z":"f93e13e54f881a08","name":"two","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","statusVal":"","statusType":"auto","x":1418,"y":200,"wires":[]},{"id":"29a3dd89320f068c","type":"debug","z":"f93e13e54f881a08","name":"three","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","statusVal":"","statusType":"auto","x":1418,"y":240,"wires":[]},{"id":"a8701d837dbac16d","type":"inject","z":"f93e13e54f881a08","name":"start here","props":[{"p":"value","v":"/one/two/three","vt":"str"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","x":787,"y":333,"wires":[["a599b0e606ad40ba"]]},{"id":"a599b0e606ad40ba","type":"switch","z":"f93e13e54f881a08","name":"","property":"param","propertyType":"msg","rules":[{"t":"hask","v":"one","vt":"str"},{"t":"hask","v":"two","vt":"str"},{"t":"hask","v":"three","vt":"str"}],"checkall":"true","repair":false,"outputs":3,"x":1221,"y":333,"wires":[["54d3261121906021"],["3f5352c74f2c136f"],["46634e3972ecde74"]]},{"id":"54d3261121906021","type":"debug","z":"f93e13e54f881a08","name":"one","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","statusVal":"","statusType":"auto","x":1424,"y":298,"wires":[]},{"id":"3f5352c74f2c136f","type":"debug","z":"f93e13e54f881a08","name":"two","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","statusVal":"","statusType":"auto","x":1424,"y":338,"wires":[]},{"id":"46634e3972ecde74","type":"debug","z":"f93e13e54f881a08","name":"three","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","statusVal":"","statusType":"auto","x":1424,"y":378,"wires":[]}]
So the bottom approach is my favourite because I don't have to open the change & the switch node to understand the flow.
Now putting this in context:
I would combine those three switch nodes into a single one - so the next consideration: how many existing nodes are there and does one more or less make a difference?
It's hard to say, very much a taste thing.
Subjectively, depends on the viewer.
But my point was this is all doable without changes to the switch node.
Sure but without change we don't have progress and without progress we don't have improvement at the risk of making things worse.
And that's why I did also say that it kind of goes against the idea that the switch node is a passive node that makes no changes to the msg object but OTOH it saves using an extra node with that, extra compute cycles.
Which does remind me of another massive and incredibly difficult project: standardisation of node functionality. Clearly defining what each node does and doesn't do. If there was a standard that said a switch is completely passive, then this would not be doable and everyone would be able to point to the standard. Until the standard is changed so that the switch can be "minimally impassive" ![]()
Btw as it stands, if this change does go into core then I have to update my collection of flow tests that attempt to standardise node functionality
so I'm in fact shooting myself in the foot. All for the sack of using one less node ...
FBP is a small logical step from flow diagrams which have been around, I rather think, from well before computer times.
Of course, both Nick and Dave were working at IBM which, for the longest time, was one of the best tech innovators on the Globe. Loads of amazing things came out of those Halcion days. ![]()
Anyway, I don't think it that strange that various, completely independent flow-based ideas came about as computers began to be more graphical in nature. What I personally find interesting was that the combination of flow-based and emerging Node.js & IoT hardware resulted in Node-RED which is, as far as I can tell, pretty unique in its approach.
As for Yahoo Pipes - I still miss it and I don't think that Node-RED comes anywhere close to a replacement really because the RSS handling is too different that the point-and-join features in Pipes. That isn't a criticism of Node-RED though, more a criticism of my own failure to be able to come up with a better solution for that one specific problem - gathering, filtering, enhancing and outputting RSS/Atom feeds. ![]()
Changes can be for the better or worse. An extra node is that a bad thing, or as you say, does it allow the flow to be more visually readable? If nodes are named clearly
yeah - of course it went downhill as soon as we left.... ![]()
Meanwhile - where are we with this discussion ? - should I bother create a PR - or just leave it as a Friday evening "that was fun" test.
(I do actually have a use case for it also - but indeed use a function/subflow to handle it at present.)
I for one would fully support a PR.
Mainly because it does have an on/off switch, its backward compatible, no active change required for users and itās default is still the same.
So I canāt see why not ā¦
I am indifferent, as i rarely use regex as a bad regex can be a resource hogger, and often there is a better way. I leave it the hands those with greater knowledge and better understanding of the node-red ethos.
Me too. But more because I'd do anything complex in a function node. I've very rarely used regex in a change node or via JSONata and never had the need to pass forward any matches.


