Skip to content

[API Proposal]: RegexOptions.Constrained #57891

@stephentoub

Description

@stephentoub

Background and motivation

The .NET regex engine today works based on an NFA/backtracking-based engine. For .NET 7, we're exploring adding an opt-in DFA-based engine. To opt-in, we'd use a new RegexOptions enum value.

API Proposal

namespace System.Text.RegularExpressions
{
     public enum RegexOptions
     {
          ...
          Constrained = 0x0400
     }
}

Other name choices could include DFA, Deterministic, Safe, Predictable, ...

API Usage

var r = new Regex(..., RegexOptions.Constrained);

Risks

It is opt-in as the engine will almost certainly have some limitations on what patterns are supported (e.g. look behinds), impact on capture semantics, etc.

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions