diff --git a/Directory.Build.props b/Directory.Build.props index 7fdde89..cc5f87b 100644 --- a/Directory.Build.props +++ b/Directory.Build.props @@ -16,8 +16,8 @@ - 1.0.121 - 1.0.24 + 1.0.123 + 1.0.28 10.0.12 diff --git a/PACKAGE_README.md b/PACKAGE_README.md new file mode 100644 index 0000000..7da8547 --- /dev/null +++ b/PACKAGE_README.md @@ -0,0 +1,40 @@ +# Cloudtoid.UrlPattern + +Match URL paths and extract named values with readable patterns. Supports prefix and exact matching, optional sections, wildcards, and regular expressions. Compiled patterns are cached for reuse. + +## Install + +Requires .NET 10 or later. + +```sh +dotnet add package Cloudtoid.UrlPattern +``` + +## Example + +```csharp +using Cloudtoid.UrlPattern; + +var engine = new PatternEngine(); +var match = engine.Match( + pattern: "exact: /category/:category/product/:product", + path: "/category/furniture/product/black-couch"); + +Console.WriteLine(match.Variables["category"]); // furniture +Console.WriteLine(match.Variables["product"]); // black-couch +``` + +Pass the URL path only, starting with `/`; exclude the scheme, host, query string, and fragment. `Match` throws when matching fails; use `TryMatch` to handle a non-match without an exception. + +## Pattern syntax + +- `:name` captures a named value. +- `*` matches characters within a path segment, excluding `/`. +- Parentheses mark optional sections, such as `/products(/:id)`. +- `exact: ` requires the entire path to match. +- `prefix: ` matches a prefix and is the default mode. +- `regex: ` enables regular expressions with named captures. + +For dependency injection, call `services.AddUrlPattern()` and inject `IPatternEngine`. + +[Full syntax and examples](https://github.com/cloudtoid/url-pattern) · [Report an issue](https://github.com/cloudtoid/url-pattern/issues) · [MIT license](https://github.com/cloudtoid/url-pattern/blob/master/LICENSE) diff --git a/src/Cloudtoid.UrlPattern/Cloudtoid.UrlPattern.csproj b/src/Cloudtoid.UrlPattern/Cloudtoid.UrlPattern.csproj index d45f8ec..16507aa 100644 --- a/src/Cloudtoid.UrlPattern/Cloudtoid.UrlPattern.csproj +++ b/src/Cloudtoid.UrlPattern/Cloudtoid.UrlPattern.csproj @@ -6,7 +6,7 @@ - README.md + PACKAGE_README.md Cloudtoid.UrlPattern Cloudtoid.UrlPattern pedram@rezaei.us @@ -23,7 +23,7 @@ - +