Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Some nice .NET snippets
.NET snippets
1. Deconstruct a regex match group collection
public static class DeconstructExtensions
{
/// <summary>
/// Deconstruct the first two matched sub-groups of a regex match to directly
/// obtain the values
/// </summary>
/// <param name="groups">the regex match groups</param>
/// <param name="val0">value 1</param>
/// <param name="val1">value 2</param>
public static void Deconstruct(this GroupCollection groups, out string val0, out string val1)
{
// group 0 is always the full match
val0 = groups[1].Value;
val1 = groups[2].Value;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.