using System.Text.RegularExpressions;
public static class Program
public static void Main()
var firstLevel = GetFirstLevel("containedItem.ttest[te.te].tes");
Console.WriteLine(firstLevel);
public static string GetFirstLevel(this string path)
if (Regex.Replace(path, @"\[.*\]", "").LastIndexOf('.') == -1) return path;
if (!path.Contains("[")) return path.Remove(path.IndexOf('.'));
return (path.IndexOf('[') < path.IndexOf('.'))
? path.Remove(path.IndexOf(']') + 1)
: path.Remove(path.IndexOf('.'));