Skip to content

BUG? Named numbered groups that are too large cannot be directly accessed #111634

@longxya

Description

@longxya

Description

If name of Named group is a number, and the number is larger than the count of Groups,using Match.Groups to check the groups in quick check in visual studio, u will find wrong infomation of this group. But u can use Match.Groups[number] to accesse this group.

Reproduction Steps

using System;
using System.Text.RegularExpressions;

var pattern = @"(?'2'.)";
//pattern = @"(?'2'.)(?'wtf')";//use this will Output normal result
var input = @"1";
var mh = Regex.Match(input,pattern);
Console.WriteLine(string.Join(",",mh.Groups.Keys)+"#");
Console.WriteLine(mh.Groups[1].Success);
Console.WriteLine(mh.Groups[2].Success);
Console.WriteLine(mh.Groups[2]);

Output:

0,#
False
True
1

Expected behavior

Output:

0,2#
False
True
1

Actual behavior

OUtput:

0,#
False
True
1

Regression?

No response

Known Workarounds

No response

Configuration

No response

Other information

No response

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions