Skip to content

Instantly share code, notes, and snippets.

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