nats-io / nats.net

The official C# Client for NATS

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Export match function

Shawak opened this issue · comments

Proposed change

  • Expose a functon to check whether or not a subject would match a filter (with wildcards)

Use case

I ran into a problem where I have to check if the subject I am receiving matches a specific wildcard subject, I searched for a function to check this but I couldnt find any

Contribution

No response

So I know there is similar logic already to this in the server as it has to be able to resolve a non-wildcard subject to the proper stream/subject. That code is pretty complex.
Also, you know more about your subjects and wildcards so could build an efficient function with that knowledge.
If you would like, you are welcome to build this and we'll consider adding it to the project.

I'm now using this to solve my issue:

    var regex = new Regex($"^{Regex.Escape(subject).Replace(@"\*", "[^.]+").Replace(@">", ".+")}$", RegexOptions.Compiled);