Skip to content

NonBacktracking regex misses a match when word-boundary alternatives repeat #135586

Open

Description

@robertmorelli

Description

RegexOptions.NonBacktracking fails to match a repeated group whose alternatives start with \b and \B. The interpreter and Compiled engines match the same input.

Reproduction Steps

using System;
using System.Text.RegularExpressions;

const string pattern = @"^a (?:\Ba|\ba)+$";
const string input = "a aa";

Console.WriteLine(new Regex(pattern).IsMatch(input)); // True

Console.WriteLine(new Regex(pattern, RegexOptions.Compiled).IsMatch(input)); // True

Console.WriteLine(new Regex(pattern, RegexOptions.NonBacktracking).IsMatch(input)); // False

Expected behavior

True (always)

Actual behavior

NonBacktracking returns False

Regression?

idk

Known Workarounds

use one of the other engines

Configuration

.NET 11.0.0-rc.1.26425.128
macOS ARM64

Other information

No response

Activity

  1. added
    untriaged
    on Oct 11, 2026
  2. dotnet-policy-service commented on Oct 11, 2026

    @dotnet-policy-service
    Contributor

    Tagging subscribers to this area: @dotnet/area-system-text-regularexpressions
    See info in area-owners.md if you want to be subscribed.

  3. added this to the Future milestone on Oct 12, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    area-System.Text.RegularExpressionsuntriaged

    Type

    No type

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions