# Switch node - MQTT like wildcards for switching

**URL:** <https://discourse.nodered.org/t/switch-node-mqtt-like-wildcards-for-switching/46337>\
**Category:** Feature Requests\
**Created:** [27 May 2021 11:54 UTC](https://discourse.nodered.org/t/switch-node-mqtt-like-wildcards-for-switching/46337 "2021-05-27T11:54:50Z")\
**Posts on this page:** 1\
**Showing post:** 58

<div class="post-metadata">

**Author:** ![Steve-Mcl](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/steve-mcl/32/4826_2.png) [@Steve-Mcl](https://discourse.nodered.org/u/Steve-Mcl)\
**Post date:** [29 May 2021 12:19 UTC](https://discourse.nodered.org/t/switch-node-mqtt-like-wildcards-for-switching/46337/58 "2021-05-29T12:19:25Z")

</div>

> [@JGKK](#):
>
> So why not just add an example to the mqtt section of the cookbook to explain how to do this

Nobody reads the docs - you have seen the forum replies "see the built in help" "see the readme" "see the cookbook" right? 😉

  

> [@dceejay](#):
>
> Topic ? What topic ?

MQTT topic (of course 🙂 )...

  

> [@knolleary](#):
>
> How would we know if a post matches the topic?

sentiment node? 😇

  

Ok, lets see if we can round this off...

### Summary

So I read from the posts in this thread there is slightly more positive consensus towards the switch node supporting this **but** there are variations on that support (mqtt filter vs more general wildcard)

### Use xxxx (arguments against it)

There are several posters saying "use regex" or "use JSONata".

The counter argument to that is, why bother having `==` or `contains` or `is true` etc - you can do these in one of regex or JSONata

Personally, I dont think "use regex" or "use JSONata" is the answer. I love the power of regex & JSONata **BUT** I almost always have to use a helper for even quite simple things.

The fact is, they are not simple, not for newbees and are inconsistent with MQTT topics.

e.g. to achieve a really simple topic filter of `+/1/+/temperature` in regex is `^[^\/\n]+\/1\/[^\/\n]+\/temperature$` 🤮

[example](https://regex101.com/r/bHRkFL/1)

### General wildcard

I do agree MQTT topic filtering is somewhat restrictive BUT as others have pointed out "which wildcards?". There is no real standard (MS versions, VB like version, SQL like, glob etc etc). I too would really like a nice easy to use `*?#` form of wildcard matching but in the context of MQTT topic filtering, I dont think it it makes a lot of sense since `*` and `?` are valid characters in a topic (not that I would ever use them) - meaning we would have to escape them.  
Perhaps this is a good and sensible proposal for simple wildcard matching & something that should be considered for the switch node but I believe it should be separate from MQTT topic filter. Perhaps we can discuss and agree in a different thread?

### MQTT topic filtering

IMHO Anyone doing MQTT knows (or will eventually learn about) topic filtering via `+/#` so i would propose if we DO add support for this, then it is just that - KISS approach.

---

_[View the full topic](https://discourse.nodered.org/t/switch-node-mqtt-like-wildcards-for-switching/46337)._
