Beispiel #1
0
		// Extension for string
		internal static string WildcardToPattern(string pattern, WildcardSearch matchType)
		{
			string escapedPattern = Regex.Escape(pattern);
			escapedPattern = escapedPattern.Replace("\\*", ".*?"); // lazy star not a greedy star
			escapedPattern = escapedPattern.Replace("\\?", ".");
			if (matchType == WildcardSearch.Exact)
				return "^" + escapedPattern + "$";
			if (matchType == WildcardSearch.Anywhere)
				return escapedPattern;
			if (matchType == WildcardSearch.StartsWith)
				return "^" + escapedPattern;
			if (matchType == WildcardSearch.EndsWith)
				return escapedPattern + "$";
			return pattern;
		}
Beispiel #2
0
        // Extension for string
        internal static string WildcardToPattern(string pattern, WildcardSearch matchType)
        {
            string escapedPattern = Regex.Escape(pattern);

            escapedPattern = escapedPattern.Replace("\\*", ".*?");             // lazy star not a greedy star
            escapedPattern = escapedPattern.Replace("\\?", ".");
            if (matchType == WildcardSearch.Exact)
            {
                return("^" + escapedPattern + "$");
            }
            if (matchType == WildcardSearch.Anywhere)
            {
                return(escapedPattern);
            }
            if (matchType == WildcardSearch.StartsWith)
            {
                return("^" + escapedPattern);
            }
            if (matchType == WildcardSearch.EndsWith)
            {
                return(escapedPattern + "$");
            }
            return(pattern);
        }