Skip to content

BUG? Compiled RegularExpression throws exception incorrectly when leaving Balancing Groups #111631

Closed

Description

@longxya

Description

Using new Regex("(.)(?'2-1'(?'-1'.))", RegexOptions.Compiled).Matches("wtf") will throw an exception "Index was outside the bounds of the array".

Reproduction Steps

using System;
using System.Text.RegularExpressions;

var pattern = @"(.)(?'2-1'(?'-1'.))";
var input = @"11";
try
{
	Match matchCompiled = new Regex(pattern, RegexOptions.Compiled).Match(input);
	Console.WriteLine($"Compiled: {matchCompiled.Success}");
}catch(Exception ex)
{
	Console.WriteLine(ex.Message);
}

Output:

Index was outside the bounds of the array.

Expected behavior

Output:

Compiled: False

Actual behavior

Output:

Index was outside the bounds of the array.

Regression?

No response

Known Workarounds

No response

Configuration

No response

Other information

No response

Activity

  1. added
    untriaged
    on Jan 20, 2025
  2. dotnet-policy-service commented on Jan 20, 2025

    @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
    in-pr
    on Jan 23, 2025
  4. added and removed
    untriaged
    on Jan 23, 2025
  5. stephentoub commented on Jan 23, 2025

    @stephentoub
    Member

    Thanks. Will be fixed by #111769.

  6. added this to the 10.0.0 milestone on Jan 27, 2025
  7. locked and limited conversation to collaborators on Feb 27, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

area-System.Text.RegularExpressionsbugin-pr

Type

No type

Projects

No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions