Lokad.Utf8Regex.Pcre2 0.3.0

Prefix Reserved
dotnet add package Lokad.Utf8Regex.Pcre2 --version 0.3.0
                    
NuGet\Install-Package Lokad.Utf8Regex.Pcre2 -Version 0.3.0
                    
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="Lokad.Utf8Regex.Pcre2" Version="0.3.0" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="Lokad.Utf8Regex.Pcre2" Version="0.3.0" />
                    
Directory.Packages.props
<PackageReference Include="Lokad.Utf8Regex.Pcre2" />
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add Lokad.Utf8Regex.Pcre2 --version 0.3.0
                    
#r "nuget: Lokad.Utf8Regex.Pcre2, 0.3.0"
                    
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
#:package Lokad.Utf8Regex.Pcre2@0.3.0
                    
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=Lokad.Utf8Regex.Pcre2&version=0.3.0
                    
Install as a Cake Addin
#tool nuget:?package=Lokad.Utf8Regex.Pcre2&version=0.3.0
                    
Install as a Cake Tool

Lokad.Utf8Regex.Pcre2

Lokad.Utf8Regex.Pcre2 is a net10.0, UTF-8-first managed companion to Lokad.Utf8Regex. Utf8Pcre2Regex implements the repository's selected PCRE2 10.47 standard-matcher profile over ReadOnlySpan<byte> and Span<byte>. Utf8Regex remains exclusively the .NET 10 Regex profile.

The package does not bind to native PCRE2. Its only non-BCL implementation dependency is Lokad.Utf8Regex; there is no P/Invoke, native loader, RID payload, or external matcher executable.

Release notes for the core and companion packages are tracked in the repository changelog.

Supported profile

The generic PCRE2 compiler/runtime covers the admitted literal, character, branching, repetition, capture, backreference, assertion, scoped-option, branch-reset, duplicate-name, recursion/subroutine, conditional, atomic, backtracking-control, \K, Unicode, and opted-in \C families. Normal operations include IsMatch, Match, MatchDetailed, Count, EnumerateMatches, MatchMany, and PCRE2 substitution.

Probe implements a curated partial-match profile and rejects unsupported partial shapes explicitly. The DFA matcher, invalid-UTF subject mode, callouts, split, full capture history, and substitution forms outside the selected profile are not included. The executable corpus and backlog ledgers are the authoritative capability boundary; support is never inferred from similarity to .NET behavior.

Patterns and subjects must be well-formed UTF-8. Public start positions and raw match ranges use byte offsets. UTF-16 coordinates are exposed only when the reported range is exactly projectable. Opted-in \C can return a byte slice that splits a scalar, and opted-in lookaround \K can report a non-monotone range; affected operations follow the explicit dispositions in SPEC-PCRE2.md.

Example

using System.Text;
using Lokad.Utf8Regex.Pcre2;

var regex = new Utf8Pcre2Regex(
    @"(?<scheme>https?)://(?<host>[A-Za-z0-9.-]+)",
    Pcre2CompileOptions.None);

ReadOnlySpan<byte> input = Encoding.UTF8.GetBytes(
    "Visit https://example.com and http://localhost.");

foreach (var match in regex.EnumerateMatches(input))
{
    if (match.Success && match.IsByteAligned)
    {
        Console.WriteLine(
            Encoding.UTF8.GetString(input.Slice(match.IndexInBytes, match.LengthInBytes)));
    }
}

byte[] redacted = regex.Replace(input, "<$host>");

Replacement strings use PCRE2 substitution syntax, not .NET replacement syntax. The API also exposes UTF-8 replacement patterns, callback replacement, TryReplace, ReplaceToString, detailed numeric-slot/name-table results, and explicit compile and execution settings.

Contract and development evidence

The public surface uses explicit overloads rather than default-valued parameters. Its exact frozen form is PublicApi.Shipped.txt. The package contract is SPEC-PCRE2.md, internal ownership is described in ARCHITECTURE.md, and release evidence is recorded in QUALIFICATION.md. The generated BENCHMARKS.md page keeps the PCRE2-specific performance snapshot, native PCRE2 baseline, dependency review, and scaling evidence local to this companion.

Run ./test-packaged-pcre2.ps1 -Configuration Release from the repository root to pack a version-coherent core/companion pair, reject native or RID assets, replace the PCRE2 test project's sibling references with package references, and execute the complete PCRE2 suite from an isolated NuGet cache.

Product Compatible and additional computed target framework versions.
.NET net10.0 is compatible.  net10.0-android was computed.  net10.0-browser was computed.  net10.0-ios was computed.  net10.0-maccatalyst was computed.  net10.0-macos was computed.  net10.0-tvos was computed.  net10.0-windows was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
0.3.0 107 8/28/2026
0.2.0 136 4/29/2026
0.1.0 130 4/13/2026