using System.Text.RegularExpressions;
private const string IMAGE_FILENAME_PATTERN = @"^(?<OrderCode>(cm[\d]{11}_[\d]{4,}|[a-z0-9]{5,})).*\.(jpg|png|jpeg)$";
private static bool IsImageFile(string path, out string orderCode)
var match = Regex.Match(path, IMAGE_FILENAME_PATTERN, RegexOptions.IgnoreCase);
if (match?.Success == true)
orderCode = match.Groups["OrderCode"].Value;
public static void Main()
bool ok = IsImageFile("CM20000289800_10018_01.jpg", out string code);
Console.WriteLine(string.Format("OK: {0}", ok));
Console.WriteLine(string.Format("order: {0}", code));