Change-node wilcard

Hi, is there a way to change “any” value in my payload to “off” via a node-red change node?

Like this:
image ?

You should be able to do this using a regular expression where you have “any value”. The regex you need would depend on what exactly you are trying to do. Are you wanting to set msg.payload to off if the existing payload contains any digit?

Yes if there is “any value” in it, it needs to be changed to “off”

Thus, I mean there can be anything in it, like a number, or text, or any.

should I just use dot?
. = any char

.+ otherwise you would get off for every character in the incoming payload. Hope that helps

I don’t seem to get it… it’s not changing the number only the value…


[{"id":"911c1a86.b6f95","type":"inject","z":"4cc3ec41.6d206c","name":"","topic":"","payload":"any","payloadType":"str","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":150,"y":880,"wires":[["1d2966a5.21b2a1","b572f3f3.14b9a8"]]},{"id":"1d2966a5.21b2a1","type":"change","z":"4cc3ec41.6d206c","name":"","rules":[{"t":"change","p":"payload","pt":"msg","from":".+","fromt":"re","to":"off","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":480,"y":860,"wires":[["b572f3f3.14b9a8"]]},{"id":"b572f3f3.14b9a8","type":"debug","z":"4cc3ec41.6d206c","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","x":810,"y":960,"wires":[]},{"id":"1016d806.7f69a","type":"inject","z":"4cc3ec41.6d206c","name":"","topic":"","payload":"123","payloadType":"num","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":130,"y":940,"wires":[["1d2966a5.21b2a1","b572f3f3.14b9a8"]]}]

So a couple of things. Firstly, the “Search for” drop-down box should have “.* regular expression” selected. Secondly will 123 be an integer or a character string? Regex works on characters. So passing “123” is different from 123 in the payload. It’s easy enough to convert. Try this…

[{"id":"22bd7a7f.283c86","type":"inject","z":"feb[18245.31](tel:1824531)d26","name":"","topic":"","payload":"any","payloadType":"str","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":150,"y":480,"wires":[["3ad3a9c8.f52e26"]]},{"id":"3ad3a9c8.f52e26","type":"change","z":"feb[18245.31](tel:1824531)d26","name":"","rules":[{"t":"change","p":"payload","pt":"msg","from":".+","fromt":"re","to":"off","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":520,"y":460,"wires":[["406a34b0.c96c3c"]]},{"id":"406a34b0.c96c3c","type":"debug","z":"feb[18245.31](tel:1824531)d26","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","x":770,"y":460,"wires":[]},{"id":"5f[30404](tel:30404)b.b490b","type":"inject","z":"feb[18245.31](tel:1824531)d26","name":"","topic":"","payload":"123","payloadType":"num","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":130,"y":540,"wires":[["[94196](tel:94196)bde.[548078](tel:548078)"]]},{"id":"[94196](tel:94196)bde.[548078](tel:548078)","type":"change","z":"feb[18245.31](tel:1824531)d26","name":"Convert","rules":[{"t":"set","p":"payload","pt":"msg","to":"$string(payload)","tot":"jsonata"}],"action":"","property":"","from":"","to":"","reg":false,"x":320,"y":540,"wires":[["3ad3a9c8.f52e26"]]}]

Ok, thank you! That works… but…

the firstly:
the “Search for” drop-down box should have “.* regular expression” selected.
–> it had:
image

the secondly:
whats the difference between an integer or character string? Does it matter? I just want to change “any value” in the msg.payload.

Leave it… I give up for now… the question relates to an issue I have with an entity but it’s too complex to even tell … Don’t know where to start.

Thanks for you support!

I think I am misunderstanding what you are trying to achieve. For example, if the incoming payload is
“This message has 100 widgets”, do you want the outgoing payload to say just “off” or “This message has off widgets”. And if the incoming payload is “This message has no widgets” do you want the outgoing payload to be “This message has no widgets” i.e. remain the same.

Just very simple…

ANY value in msg.payload, “chicken”, “123pasta”, “2938383” to “off” :slight_smile:

I think this is what you are looking for

[{"id":"22bd7a7f.283c86","type":"inject","z":"feb18245.31d26","name":"","topic":"","payload":"any","payloadType":"str","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":110,"y":460,"wires":[["94196bde.548078"]]},{"id":"406a34b0.c96c3c","type":"debug","z":"feb18245.31d26","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","x":770,"y":460,"wires":[]},{"id":"5f30404b.b490b","type":"inject","z":"feb18245.31d26","name":"","topic":"","payload":"123","payloadType":"num","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":110,"y":520,"wires":[["94196bde.548078"]]},{"id":"94196bde.548078","type":"change","z":"feb18245.31d26","name":"Convert","rules":[{"t":"set","p":"payload","pt":"msg","to":"$string(payload)","tot":"jsonata"}],"action":"","property":"","from":"","to":"","reg":false,"x":280,"y":460,"wires":[["e8bc87a1.22cf68"]]},{"id":"8e2d0d53.7ad73","type":"inject","z":"feb18245.31d26","name":"","topic":"","payload":"123abcdef567nbfd","payloadType":"str","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":150,"y":580,"wires":[["94196bde.548078"]]},{"id":"e8bc87a1.22cf68","type":"switch","z":"feb18245.31d26","name":"","property":"payload","propertyType":"msg","rules":[{"t":"nempty"}],"checkall":"false","repair":false,"outputs":1,"x":450,"y":460,"wires":[["c73bd658.6ee4f8"]]},{"id":"c73bd658.6ee4f8","type":"change","z":"feb18245.31d26","name":"Set","rules":[{"t":"set","p":"payload","pt":"msg","to":"off","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":610,"y":460,"wires":[["406a34b0.c96c3c"]]},{"id":"c88f2f32.963d4","type":"inject","z":"feb18245.31d26","name":"Empty","topic":"","payload":"","payloadType":"str","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":110,"y":640,"wires":[["94196bde.548078"]]}]

Hm… seems to be not so simple…I think it is a language-terminology-waynoderedworks-kinda thing.

I am now testing your 3 nodes if the do what I want…

In this case, just why not using “set” instead of “change”. It will put the value you want in msg.payload.

GV