Dynamic groups based on mqtt topic

Hi everyone,

I’m using zigbee2mqtt and renamed all my devices in such a way that they follow the logic of my building:

my/level/room/type/id/description

i.e.

my/n00/p00/switch/S01/midden
my/n00/p00/switch/S05/voordeur
my/n00/p03/light/L19/hanglamp
my/n01/p01/temperature/T02/nachtkastje
my/n01/p01/vibration/A01/nachtkastje
my/n01/p02/contact/C04/venster rechts
my/n02/p00/switch/S04/wandschakelaar
....

where

n00 = floorlevel 0
p03 = place 3

etc…

So I’m wondering if it is possible to create groups based on this logic
all entities of level 00:

my/n00/#

all entities of “all rooms 2” (the same roomlocation, but on different levels)

my/#/p02/#

all entities of room 01.02

my/n01/p02/#

all switches

my/#/#/switch/#

etc…

If this could be done by script, is ok. I’m not adding everyday a new device, so I could run the script from time to time.

if there is a way to have things organized fully automatic, it would even be better.

Any help/suggestion/solution is appreciated.

thanx in advance,
Bart