Matching Wildcards in Sitecore

While reading this nice blog post by my colleague Uli about resolving a Sitecore SiteContext from an URI I noticed that he used a regex to match a hostname using * as a wildcard

That made me remember the Sitecore class called Sitecore.Text.WildcardParser. I once wrote a blog post about this class but I never got around to publish it. So now I’ll try again and keep it short.

The WildcardParser class is pretty unknown even though it is an oldie in the Sitecore API. It can be used to match a string value with an array of strings where a * means wildcard. It is used by Sitecore to check if a SiteInfo class matches a hostname. An example usage of the class could look like this:

The SiteInfo class itself contain a boolean method called Matches(string host) that uses the WildCardparser to check if the hostname matches the SiteInfo hostname.

That was it. I will post another quick Sitecore Sunday tip today on sending emails using the Sitecore API.

Anders Laub

Anders Laub Christoffersen

Anders has been working with Sitecore for over a decade and has in this time been the lead developer and architect on several large scale enterprise solutions all around the world. Anders was appointed the title of Sitecore Technical MVP in 2014 and has been re-appointed the title every year since then.

Leave a Reply

Your email address will not be published. Required fields are marked *