Last active
May 1, 2023 15:36
-
-
Save 5cover/a32c4ea1967563ca7de37e391d1e1e13 to your computer and use it in GitHub Desktop.
C# Tuple assignement Regex
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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