# Matches Regex SwitchNode

**URL:** <https://discourse.nodered.org/t/matches-regex-switchnode/40035>\
**Category:** General\
**Created:** [30 January 2021 08:54 UTC](https://discourse.nodered.org/t/matches-regex-switchnode/40035 "2021-01-30T08:54:07Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![nicedevil](https://avatars.discourse-cdn.com/v4/letter/n/858c86/32.png) [@nicedevil](https://discourse.nodered.org/u/nicedevil)\
**Post date:** [30 January 2021 08:54 UTC](https://discourse.nodered.org/t/matches-regex-switchnode/40035/1 "2021-01-30T08:54:07Z")

</div>

Heya, found this great snipped here in [Node-RED Forum](https://discourse.nodered.org/t/how-to-build-an-jsonata-for-this-switch-node/32836/8)

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:

`shelly.0.SHPLG-S#2029FD#1.Relay0.Switch`

or

`shelly.0.SHPLG-S#7085AC#1.Relay0.Switch`

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 🙂

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

---

<div class="post-metadata">

**Author:** ![zenofmud](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/zenofmud/32/316_2.png) [@zenofmud](https://discourse.nodered.org/u/zenofmud)\
**Post date:** [30 January 2021 08:57 UTC](https://discourse.nodered.org/t/matches-regex-switchnode/40035/2 "2021-01-30T08:57:30Z")

</div>

Use the ‘contains’ option in the switch

---

<div class="post-metadata">

**Author:** ![nicedevil](https://avatars.discourse-cdn.com/v4/letter/n/858c86/32.png) [@nicedevil](https://discourse.nodered.org/u/nicedevil)\
**Post date:** [30 January 2021 08:59 UTC](https://discourse.nodered.org/t/matches-regex-switchnode/40035/3 "2021-01-30T08:59:20Z")

</div>

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 ☹

---

<div class="post-metadata">

**Author:** ![dceejay](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/dceejay/32/38_2.png) [@dceejay](https://discourse.nodered.org/u/dceejay)\
**Post date:** [30 January 2021 09:02 UTC](https://discourse.nodered.org/t/matches-regex-switchnode/40035/4 "2021-01-30T09:02:25Z")

</div>

Wire both to the same place

---

<div class="post-metadata">

**Author:** ![nicedevil](https://avatars.discourse-cdn.com/v4/letter/n/858c86/32.png) [@nicedevil](https://discourse.nodered.org/u/nicedevil)\
**Post date:** [30 January 2021 09:03 UTC](https://discourse.nodered.org/t/matches-regex-switchnode/40035/5 "2021-01-30T09:03:43Z")

</div>

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 😃

---

<div class="post-metadata">

**Author:** ![dceejay](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/dceejay/32/38_2.png) [@dceejay](https://discourse.nodered.org/u/dceejay)\
**Post date:** [30 January 2021 09:05 UTC](https://discourse.nodered.org/t/matches-regex-switchnode/40035/6 "2021-01-30T09:05:44Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![nicedevil](https://avatars.discourse-cdn.com/v4/letter/n/858c86/32.png) [@nicedevil](https://discourse.nodered.org/u/nicedevil)\
**Post date:** [30 January 2021 09:09 UTC](https://discourse.nodered.org/t/matches-regex-switchnode/40035/7 "2021-01-30T09:09:06Z")

</div>

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

 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/c/1/c12db630c55111dd14bb3aea54adc6e7f089271c.png)

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/1X/d073cd938eafa2e558d7c2cd59003b3ef4963033.png) [@system](https://discourse.nodered.org/u/system)\
**Post date:** [13 February 2021 09:09 UTC](https://discourse.nodered.org/t/matches-regex-switchnode/40035/8 "2021-02-13T09:09:19Z")

</div>

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