I am trying to find out a URL which belongs to :
http://domain.blob.core.windows.net/
https://domain.blob.core.windows.net/
http://domain.blob.core.windows.net
https://domain.blob.core.windows.net
The regex which I wrote
Regex reg2= new Regex(@"^http(s?)://[0-9a-zA-Z](.blob.core.windows.net)(/?)$");
string url = "http://abc.blob.core.windows.net";
if(reg2.IsMatch(url))
{
Console.WriteLine("Yes");
}
else
{
Console.WriteLine("no");
}
I am not able to find the match. It’s not working 🙁 I am pretty weak in regex. So can anyone help me to find out my mistake? I am using c#. It always prints no.
UPDATE : FINAL Answer which worked for me:
Regex reg2 = new Regex(@"^http(s?)\:\/\/[0-9a-zA-Z]*(\.blob\.core\.windows\.net)
(/?)$");
Just in case anybody needs something like this 🙂
You were close with
"^http(s?)://[0-9a-zA-Z](.blob.core.windows.net)(/?)$"however[0-9a-zA-Z]should be[0-9a-zA-Z]+as you want to be multiple characters before.blob.core.windows.netnot just a single character.Note: you don’t need brackets here if you not capturing parts of the match, the optional operator is applied to the previous character only so
^https?$matches'http'or'https'and not''as only thesis optional, Also escape all.characters as inregexthe.characters matches any single character so to match a literal.you want\..