Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/335.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C#Regex我怎么能缩短所有这些匹配_C#_.net_Regex - Fatal编程技术网

C#Regex我怎么能缩短所有这些匹配

C#Regex我怎么能缩短所有这些匹配,c#,.net,regex,C#,.net,Regex,我如何缩短一些,是否有任何正则表达式类函数来重新组合许多匹配项 var match = Regex.Match(GetActiveWindowTitle(), "(?i)ab.*?"); var match2 = Regex.Match(GetActiveWindowTitle(), "(?i)bc.*?"); var match3 = Regex.Match(GetActiveWindowTitle(), "(?i)de.*?"); var match4 = R

我如何缩短一些,是否有任何正则表达式类函数来重新组合许多匹配项

    var match = Regex.Match(GetActiveWindowTitle(), "(?i)ab.*?");
    var match2 = Regex.Match(GetActiveWindowTitle(), "(?i)bc.*?");
    var match3 = Regex.Match(GetActiveWindowTitle(), "(?i)de.*?");
    var match4 = Regex.Match(GetActiveWindowTitle(), "(?i)ef.*?");
    var match5= Regex.Match(GetActiveWindowTitle(), "(?i)gh.*?");
    var match6= Regex.Match(GetActiveWindowTitle(), "(?i)ij.*?");
    var match7 = Regex.Match(GetActiveWindowTitle(), "(?i)kl.*?");

 if (match4.Success || match.Success || match2.Success || match3.Success etc....)
            {
                MessageBox.Show("Sucess");
            }
使用管道
|
标记进行替换

请注意,
?:
表示这些是“非捕获括号”。这是可选的,但通常是为了性能而进行的,以表示不需要捕获括号内的内容(默认行为)。在本例中,我们仅使用括号括起替代选项

使用管道
|
标记进行替换

请注意,
?:
表示这些是“非捕获括号”。这是可选的,但通常是为了性能而进行的,以表示不需要捕获括号内的内容(默认行为)。在本例中,我们仅使用括号括起替代选项

"(?i)(?:ab|bc|de|ef|gh|ij|kl).*?"