Need to perform Wildcard (*,?, etc) search on a string using Regex

后端 未结 10 2383
执笔经年
执笔经年 2020-11-27 04:35

I need to perform Wildcard (*, ?, etc.) search on a string. This is what I have done:

string input = \"Message\";
string pattern =          


        
10条回答
  •  轻奢々
    轻奢々 (楼主)
    2020-11-27 05:16

    The correct regular expression formulation of the glob expression d* is ^d, which means match anything that starts with d.

        string input = "Message";
        string pattern = @"^d";
        Regex regex = new Regex(pattern, RegexOptions.IgnoreCase);
    

    (The @ quoting is not necessary in this case, but good practice since many regexes use backslash escapes that need to be left alone, and it also indicates to the reader that this string is special).

提交回复
热议问题