How to do it...

  1. A really nice way to do this is to use an extension method. This way, you can call the extension method directly on the filename variable and have it validated. In your console application, start off by adding a new class called CustomRegexHelper with public static modifier:
        public static class CustomRegexHelper         {               }
  1. Add the usual extension method code to the CustomRegexHelper class and call the ValidAcmeCompanyFilename method:
        public static bool ValidAcmeCompanyFilename(this string  value)         {                  }
  1. Inside your ValidAcmeCompanyFilename method, add the following regex. We will explain the makeup of this regex in the How it works... section of this recipe:
 return Regex.IsMatch(value, $@"^acm[_]{DateTime.Now.Year}[_] ...

Get C# 7 and .NET Core Cookbook now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.