Regular expression capturing more than expected
2 answers
If you check what matches will be generated, it becomes clear. Add this to your code:
var matches = regex.Matches("https://foo.com");
foreach (Match match in matches)
{
Console.WriteLine(match.Value);
}
And you will see what is https:/
matched and replaced, /
matched and replaced (since it https:
is optional) and foo.com
remains.
+4
source to share