Skip to content

Instantly share code, notes, and snippets.

@jfversluis
Last active July 9, 2020 12:50
Embed
What would you like to do?
Using Regex Named Groups in C#
var azureDevOpsUrl = "https://dev.azure.com/jfversluis";
var resultUrl = "";
var azureDevOpsMatch = Regex.Match(azureDevOpsUrl, "(?<protocol>http[s]?://)(?<domainandpath>dev.azure.com/(?<accountname>[a-zA-Z]*)(.*))", RegexOptions.IgnoreCase);
if (azureDevOpsMatch.Success)
{
resultUrl = $"{azureDevOpsMatch.Groups["protocol"]}{azureDevOpsMatch.Groups["accountname"]}@{azureDevOpsMatch.Groups["domainandpath"]}";
}
Console.WriteLine(resultUrl);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment