public static void Main()
var filter = "(?i)^branches/branch/(a|d)/asdf$";
var caretIndex = filter.IndexOf('^');
var startIndex = caretIndex == -1 ? 0 : caretIndex + 1;
var sanitizedFilter = filter[startIndex..];
Console.WriteLine($"Sanitized filter: {sanitizedFilter}");
Xeger xeger = new Xeger(sanitizedFilter, new Random());
string example = xeger.Generate();
Console.WriteLine($"Xeger result: {example}");
var diffIndex = FindFirstDifferenceIndex(sanitizedFilter, example);
var path = sanitizedFilter[..diffIndex];
var endIndex = path.LastIndexOf(Path.DirectorySeparatorChar) + 1;
Console.WriteLine($"\nFinal base path: {path}");
public static int FindFirstDifferenceIndex(string str1, string str2)
int minLength = Math.Min(str1.Length, str2.Length);
for (int i = 0; i < minLength; i++)
if (str1.Length != str2.Length)