- 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 { }
- Add the usual extension method code to the CustomRegexHelper class and call the ValidAcmeCompanyFilename method:
public static bool ValidAcmeCompanyFilename(this string value) { }
- 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}[_] ...