lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]


> Only the first three are allowed to match, so "/sport.*" is not an
> option as that would match the forth one as well. On the other hand
> "/sport/.*" would not match the first one.

Other answers already suggested using regex, but if you want to stick
with Lua patterns, then using frontier pattern may be an option. I'd
expect `match("/sport%f[%W]")` to match /sport with optional path
(/sport/, sport/racing, etc.) and not match /sporting, as the frontier
pattern requires a transition from %w set to %W set.

Paul.

On Wed, Dec 14, 2022 at 12:54 PM Tristan Kohl <tristankohl@web.de> wrote:
>
> Hi folks,
>
> I am implementing a module that mimics a MQTT broker. For this I am
> transforming topics passed to the register function so I can run
> string.match() on incoming messages.
>
> Right now I am stuck how to correctly handle the multilevel wildcard:
> http://docs.oasis-open.org/mqtt/mqtt/v3.1.1/os/mqtt-v3.1.1-os.html#_Toc398718107
>
> Suppose the topic filter "/sport/#" and these published message topics:
> /sport
> /sport/racing
> /sport/racing/champion
> /sporting
>
> Only the first three are allowed to match, so "/sport.*" is not an
> option as that would match the forth one as well. On the other hand
> "/sport/.*" would not match the first one.
>
> Any ideas?
>
> Cheers
> Tristan