Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions Directory.Build.props
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@

<!-- Product Package Versions -->
<PropertyGroup>
<CloudtoidFrameworkVersion>1.0.121</CloudtoidFrameworkVersion>
<CloudtoidCodeAnalysisVersion>1.0.24</CloudtoidCodeAnalysisVersion>
<CloudtoidFrameworkVersion>1.0.123</CloudtoidFrameworkVersion>
<CloudtoidCodeAnalysisVersion>1.0.28</CloudtoidCodeAnalysisVersion>
<MicrosoftExtensionsVersion>10.0.12</MicrosoftExtensionsVersion>
</PropertyGroup>

Expand Down
40 changes: 40 additions & 0 deletions PACKAGE_README.md
Original file line number Diff line number Diff line change
@@ -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)
4 changes: 2 additions & 2 deletions src/Cloudtoid.UrlPattern/Cloudtoid.UrlPattern.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

<!-- NuGet Packaging -->
<PropertyGroup>
<PackageReadmeFile>README.md</PackageReadmeFile>
<PackageReadmeFile>PACKAGE_README.md</PackageReadmeFile>
<PackageId>Cloudtoid.UrlPattern</PackageId>
<Title>Cloudtoid.UrlPattern</Title>
<Authors>pedram@rezaei.us</Authors>
Expand All @@ -23,7 +23,7 @@
</PropertyGroup>

<ItemGroup>
<None Include="../../README.md" Pack="true" PackagePath="/" />
<None Include="../../PACKAGE_README.md" Pack="true" PackagePath="/" />
</ItemGroup>

</Project>