https://github.com/jchristn/urlmatcher
Simple URL matcher library allowing you to match based on explicit string or parameters
https://github.com/jchristn/urlmatcher
csharp dotnet dotnet-core match nuget url
Last synced: about 1 year ago
JSON representation
Simple URL matcher library allowing you to match based on explicit string or parameters
- Host: GitHub
- URL: https://github.com/jchristn/urlmatcher
- Owner: jchristn
- License: mit
- Created: 2021-02-22T16:41:49.000Z (over 5 years ago)
- Default Branch: main
- Last Pushed: 2025-01-07T14:52:06.000Z (over 1 year ago)
- Last Synced: 2025-04-24T00:07:42.179Z (about 1 year ago)
- Topics: csharp, dotnet, dotnet-core, match, nuget, url
- Language: C#
- Homepage:
- Size: 819 KB
- Stars: 6
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- Contributing: CONTRIBUTING.md
- License: LICENSE.md
- Code of conduct: CODE_OF_CONDUCT.md
Awesome Lists containing this project
README

# UrlMatcher
[](https://www.nuget.org/packages/UrlMatcher/) [](https://www.nuget.org/packages/UrlMatcher)
Simple URL matcher library allowing you to match based on explicit string or parameters, targeted to .NET Core, .NET Standard, and .NET Framework.
## Help or Feedback
First things first - do you need help or have feedback? File an issue here! We'd love to hear from you.
## New in v3.0.0
- Refactor to support both static methods and instances
- Instances take either a `Uri` or `string` (URL)
## It's Really Easy... I Mean, REALLY Easy
Refer to the ```Test``` project for a working example.
### Simple Static Method
Use the static method when you need to compare an input URL against a pattern once.
```csharp
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");
}
```
### Instance Method
Instantiate the class by supplying the URI or URL. Using the instance method eliminates the need to repeatedly parse the input URI or URL.
```csharp
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");
}
```
## Version History
Please refer to CHANGELOG.md.