Hi all, following on from the thread Switch node - MQTT like wildcards for switching that was raised following some interesting points in this thread, it is proposed that it would be ultimately more beneficial to everyone to have a wildcard option for switch routing.
This wildcard option would be more flexible than MQTT filter while being simpler than regex and JSONata and so being more accessible.
Several of the folk who commented on the previous thread alluded to the familiar format of using *, ?, #
. This is a pretty common syntax as described here on wikipedia and here in MS docs
Examples...
Wildcard | Description | Example | Matches | Does not match |
---|---|---|---|---|
* |
matches any number of any characters including none | *Law* |
Law , GrokLaw , or Lawyer . |
La , or aw
|
# |
matches any single number | no# |
no1 , no2 ~ no9
|
nod or o2 or no
|
? |
matches any single character | ?at |
Cat , cat , Bat or bat
|
at |
[abc] |
matches one character given in the bracket | [CB]at |
Cat or Bat
|
cat , bat or CBat
|
[!abc] |
Dont match one character given in the bracket | [!CB]at |
Rat or Hat
|
Cat , Bat or CBat
|
[a-z] |
matches one character from the (locale-dependent) range given in the bracket | Letter[0-9] |
Letter0 , Letter1 , Letter2 up to Letter9
|
Letters , Letter or Letter10
|
With regards to MQTT topic matching, this would now be expressed as...
MQTT filter | glob style |
---|---|
# |
?* |
home/# |
home/?* |
home/+/# |
home/?*/?* |
home/+/temperature |
home/?*/temperature |
home/+/+/sensors/# |
home/?*/?*/sensors/?* |
home/+ |
not possible (*1 ) |
home/+/+ |
not possible (*2 ) |
*1 : home/+
not possible - closest possible filter is home/?*
but that will not stop at level 2
*2 : home/+/+
not possible - closest possible filter is home/?*/?*
but that will not stop at level 3
Discussion points...
- Add
+
as a wildcard with the definition of "1 or more characters up to a/
" to handle points (*1) & (*2) ? - Support for Digraph Characters (e.g.
æ
would equala
ande
)? - Support for Collating Sequence (e.g.
[A–E]
matchesA
,Ă€
,B
,C
,D
andE
. The range does not matchĂŠ
because accented characters collate after unaccented characters in the sort order)?
Personal thoughts...
Firstly, apologies up front, I mean no offence to anyone, these are personal thoughts and musings.
I might be wrong (it happens) but as I write this up, I see enough limitations and complexity in implementation that makes me think this wildcard proposal is a case of more effort than benefit considering regex does it all + more. And please don't bite my head off here but I think this tells a tale - there is possibly some mileage in the originally proposed MQTT filter (suitably simple for its purpose at 20 lines of code!). I no longer know TBH :sigh: (sorry folks)
That said, lets see where this goes - perhaps I am to close to this - fresh eyes never hurt
Ideas / thoughts / comments below please