Simple URL matcher library allowing you to match based on explicit string or parameters
$ dotnet add package UrlMatcherSimple URL matcher library allowing you to match based on explicit string or parameters, targeted to .NET Core, .NET Standard, and .NET Framework.
First things first - do you need help or have feedback? File an issue here! We'd love to hear from you.
Uri or string (URL)Refer to the Test project for a working example.
Use the static method when you need to compare an input URL against a pattern once.
using UrlMatcher;
string pattern = "/{version}/users/{userId}";
NameValueCollection vals = null;
if (Matcher.Match("/v1.0/users/42", pattern, out vals))
{
Console.WriteLine("Match!");
Console.WriteLine(" version : " + vals["version"]); // v1.0
Console.WriteLine(" userId : " + vals["userId"]); // 42
}
else
{
Console.WriteLine("No match");
}
Instantiate the class by supplying the URI or URL. Using the instance method eliminates the need to repeatedly parse the input URI or URL.
using UrlMatcher;
Matcher matcher = new Matcher("/v1.0/users/42");
NameValueCollection vals = null;
if (matcher.Match("/{version}/users/{userId}")) // do something
else if (matcher.Match("/{version}/hobbies/{hobbyId}")) // do something
else
{
Console.WriteLine("No match");
}
Please refer to CHANGELOG.md.