Skip to content

Instantly share code, notes, and snippets.

@5cover
Last active May 1, 2023 15:36
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save 5cover/a32c4ea1967563ca7de37e391d1e1e13 to your computer and use it in GitHub Desktop.
Save 5cover/a32c4ea1967563ca7de37e391d1e1e13 to your computer and use it in GitHub Desktop.
C# Tuple assignement Regex
using System;
using System.Linq;
using System.Text.RegularExpressions;
using System.Text;
string str = @"
a1 = b1;
a2 = b2;
a3 = b3;";
var matches = new Regex(@"\s*(\S+) = (\S+);").Matches(str);
Console.WriteLine(new StringBuilder("(")
.AppendJoin(", ", matches.Select(m => m.Groups[1].Value))
.Append(") = (")
.AppendJoin(", ", matches.Select(m => m.Groups[2].Value))
.Append(')'));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment