You can do this in one regex, in both C # and Ruby, but why bother?
You have not exactly determined what you want - you must first document this. Once you have registered it, it's easy to turn this description into regular code. I think this is more readable and most important:
static bool isMainFile(string name)
{
string extension = Path.GetExtension(name);
if (extension == ".001")
return true;
if (extension != ".rar")
return false;
Match match = Regex.Match(name, @"\.part(\d+)\.rar$");
if (!match.Success)
return true;
string partNumber = match.Groups[1].Value.TrimStart('0');
return partNumber == "1";
}
, , Path . , , , .
, , , - .