TinySite.Commands.LoadSiteConfigCommand.ConvertFileGlobbingToRegex C# (CSharp) Method

ConvertFileGlobbingToRegex() private static method

private static ConvertFileGlobbingToRegex ( string pattern ) : string
pattern string
return string
        private static string ConvertFileGlobbingToRegex(string pattern)
        {
            const string findFolder = @"[^?:|""<>]*";
            const string findFolderAccidentalMatch = @"[^?:|""<>]";
            const string findFile = @"[^\\/?:|""<>]*?";

            var clean = pattern.Replace(@"\", @"\\");

            clean = clean.Replace("/", @"\\");

            clean = clean.Replace(".", @"\.");

            clean = clean.Replace("?", ".");

            var regex = clean.Replace(@"**\\", findFolder + @"\\?").Replace("**", findFolder);

            for (var index = regex.IndexOf('*'); index > -1; index = regex.IndexOf('*', index + 1))
            {
                var before = index == 0 ? String.Empty : regex.Substring(0, index);
                var after = regex.Substring(index + 1);

                if (!before.EndsWith(findFolderAccidentalMatch))
                {
                    regex = before + findFile + after;

                    index += findFile.Length + 1;
                }

                if (index + 1 >= regex.Length)
                {
                    break;
                }
            }

            return "^" + regex + "$";
        }