Skip to content

Instantly share code, notes, and snippets.

@jfversluis
Last active July 9, 2020 12:50
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 jfversluis/560a387f3815711e342cbda04dcc3d1e to your computer and use it in GitHub Desktop.
Save jfversluis/560a387f3815711e342cbda04dcc3d1e to your computer and use it in GitHub Desktop.
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