// Find all the braces subgroups
preg_match_all( '%\{([^\}.]+)+\}%', $pattern, $matches );
// Replace commas by vertical bars and wrap values with parentheses
$new_parens= array();
foreach ($matches[1] as $k => $match) {
$new_parens[$k]= preg_replace( '%,%', '|', $match );
$new_parens[$k]= "(" . $new_parens[$k] . ")";
}
// We will use this pattern to replace the braces by our parentheses alternative patterns
$old_braces= preg_replace( '%.+%', '%$0%', $matches[0] );
// Prepare the vague pattern using stars rather than possible values in braces
$stars_pattern= preg_replace( '%\{([^\}.]+)+\}%', '*', $pattern );
// Prepare the parentheses version of the pattern
$parens_pattern= preg_replace( $old_braces, $new_parens, $pattern );
// Get all the files that could match our pattern
$files_list= Utils::glob( $stars_pattern, ($flags-128) );
// Filter out non-matching files
$result= preg_grep( "%" . $parens_pattern . "%i", $files_list );
// Return a reindexed array, else there could be missing keys
$result= array_values($result);