Skip to content

Wrong answer on non-backtracking regex #135332

Closed

Description

@robertmorelli

Description

non-backtracking regex fails to match on newline alternate with preceding alternate being any 254 length string of distinct characters

Reproduction Steps

using System;
using System.Linq;
using System.Text.RegularExpressions;

var p = string.Concat(Enumerable.Range(0x4E00, 254).Select(c => (char)c)) + "|\\n";
Console.WriteLine(new Regex(p, RegexOptions.NonBacktracking).IsMatch("\n"));

Expected behavior

prints true

Actual behavior

prints false even though \n is obviously a valid alternate

Regression?

IDK

Known Workarounds

None

Configuration

.NET 10.0.12
macOS 27.0
ARM64

Other information

using System;
using System.Linq;
using System.Text.RegularExpressions;

var p = string.Concat(Enumerable.Range(0x4E00, 253).Select(c => (char)c)) + "|\\n";
Console.WriteLine(new Regex(p, RegexOptions.NonBacktracking).IsMatch("\n"));

if the range is shrunk to 253 it works

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

    Possibly fixed by #120622

  4. MihaZupan commented on Oct 19, 2026

    @MihaZupan
    Member

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

  5. removed
    untriaged
    on Oct 19, 2026
  6. 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