Skip to content

Regex empty string alternate does not match correctly #135329

Description

@robertmorelli

Description

The regex pattern "(?:a+|){2}" does not match the input "a" for both compiled and interpreted regex.

Reproduction Steps

using System;
using System.Text.RegularExpressions;

var re = new Regex("(?:a+|){2}", RegexOptions.None); // also works with .Compiled
Console.WriteLine(re.IsMatch("a"));

https://dotnetfiddle.net/Py6Nmf

Expected behavior

prints True as the pattern matches the input

Actual behavior

prints False

Regression?

IDK

Known Workarounds

An empty string alternate can be replaced with \\b|\\B

Configuration

.NET 10.0.12
macOS 27.0
ARM64

Other information

No response

Activity

  1. added
    untriaged
    on Oct 7, 2026
  2. dotnet-policy-service commented on Oct 7, 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 and removed
    untriaged
    on Oct 7, 2026
  4. added this to the 12.0.0 milestone on Oct 7, 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

    Type

    No type

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions