netstandard - Regular Expression, Group Name inaccessible

Viewed 821

In .NET Core and .NET Framework 4.x the following code works as expected:

var match = Regex.Match(src, pattern)
    .Groups
    .Cast<Group>()
    .Where(grp => grp.Name.StartsWith("val"));

However, in netstandard, the Name property in Group is gone. I'm wondering if there is a new way of achieving the same thing, or if this is a bug.


Edit: I first thought this was a netstandard 2.0 issue, but it looks like the property is missing from all netstandard versions.

Workaround for now: .Where(grp => ((string)((dynamic)grp).Name).StartsWith("val")), which is obviously less than ideal.

2 Answers

Named groups could be accessed through Regex.GetGroupNames(), it works on .NET Standard either.

Useful sample found at Regex.GetGroupNames Method

Related