Matches Regex SwitchNode

Heya, found this great snipped here in Node-RED Forum

There was explained on how to get a message checked for its string. But in this case it must be exactly the right string, what do I have to do if I have to check if the string is just inside the a bigger string?

In my concrete case I want to test if the msg.topic contains 2029FD or 7085AC and the topic looks like this:




This switch node will have multiple other topics going in. So the "contains" option will not help because those 2 should go to the same output.

Sure I can do it with the looooooooooooooong string but it is my goal to make it as clean as possible :slight_smile:

EDIT: added the description why contains isn't a solution for me :frowning:

Use the ā€˜containsā€™ option in the switch

thank you, but this won't help because I have 8 strings coming in and 2 of them should go to the same output. Sry that wasn't told you with my original post :frowning:

Wire both to the same place

That was one solution from a guy in the post I linked... but thought that it is possible with the regex.
Regex seems not a thing most people like, because it is complicated right :smiley:

Correct, by the time you have looked up how to do it and tested it you could have wired up two outputs and had a cup of coffee and walked the dog.


Ok, I did the part with the coffee, because I have no dog I found the solution :smiley:
was too simple... sometimes I start to think to complicated than the solution would be...

1 Like

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