Skip to content

Regex interpreter hangs #135328

Closed
Closed

Description

@robertmorelli

Description

The regex pattern "(?:|a?|b)+?c" applied to "a" does not terminate on interpreted regex.

Reproduction Steps

using System;
using System.Text.RegularExpressions;

var re = new Regex("(?:|a?|b)+?c", RegexOptions.None);
Console.WriteLine(re.IsMatch("a"));

https://dotnetfiddle.net/oe7YtN

Expected behavior

This should print false

Actual behavior

It loops infinitely (or runs out of memory as it does on dotnetfiddle)

Regression?

IDK

Known Workarounds

Compiled regex does not hang (RegexOptions.None swapped for RegexOptions.Compiled)

using System;
using System.Text.RegularExpressions;

var re = new Regex("(?:|a?|b)+?c", RegexOptions.Compiled);
Console.WriteLine(re.IsMatch("a"));

Configuration

.NET 10.0.12
macOS 27.0
ARM64

Other information

The pattern "(?:|a*|b)*?c" applied to "a" has the same behavior and is likely the same bug.

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. MihaZupan commented on Oct 7, 2026

    @MihaZupan
    Member

    Have you tried to reproduce the issue on .NET 11? This may have been fixed by #120872

  4. hez2010 commented on Oct 8, 2026

    @hez2010
    Contributor

    Doesn't seem to repro on .NET 11.
    It does repro on .NET 10 though.

  5. MihaZupan commented on Oct 19, 2026

    @MihaZupan
    Member

    I'll close this as fixed, feel free to comment again if you see otherwise

  6. removed
    untriaged
    on Oct 19, 2026
  7. locked and limited conversation to collaborators on Nov 19, 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

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions