public static void Main()
var filter = "^branches/branch/.*/(a|d)/asdf";
Xeger xeger = new Xeger(filter, new Random(1));
string example = xeger.Generate();
Console.WriteLine($"Xeger result: {example}");
var path = GetLargestCommonSubstring(filter, example);
var endIndex = path.LastIndexOf(Path.DirectorySeparatorChar) + 1;
Console.WriteLine($"\nFinal base path: {path}");
public static string GetLargestCommonSubstring(string str1, string str2)
int[,] dp = new int[str1.Length + 1, str2.Length + 1];
for (int i = 1; i <= str1.Length; i++)
for (int j = 1; j <= str2.Length; j++)
if (str1[i - 1] == str2[j - 1])
dp[i, j] = dp[i - 1, j - 1] + 1;
if (dp[i, j] > maxLength)
return str1.Substring(endIndex - maxLength, maxLength);