Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/289.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

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/regex/17.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# 用于短语搜索的正则表达式_C#_Regex_Linq_Pattern Matching_Phrase - Fatal编程技术网

C# 用于短语搜索的正则表达式

C# 用于短语搜索的正则表达式,c#,regex,linq,pattern-matching,phrase,C#,Regex,Linq,Pattern Matching,Phrase,我必须在大字符串中搜索短语,长度可能为500或600或更大,现在我必须检查短语是否存在 phrase = "Lucky Draw" big string1 = "I'm looking for Lucky Draw a way to loop through the sentences and check" big string1 = "I'm looking for specialLucky Draw a way to loop through the sentences and

我必须在大字符串中搜索短语,长度可能为500或600或更大,现在我必须检查短语是否存在

 phrase =  "Lucky Draw"

big string1  = "I'm looking for Lucky Draw a way to loop through the sentences and check"

big string1  = "I'm looking for  specialLucky Draw a way to loop through the sentences and check"

big string3  = "I'm looking for Lucky Draws a way to loop through the sentences and check"

bool success = Regex.Match(message, @"\bLucky Draw\b").Success;
我正在做上述解决方法,但它不能满足所有情况

当我有多个短语时,我要做的是在这种情况下使用
linq
,如:

bool success = Regex.Match(message,  **arrayofstrings**).Success;

您可以使用循环从短语数组中构建一个大型正则表达式
\b(短语一|短语二|短语三|等)
,然后使用该正则表达式与字符串匹配。

哪些情况不匹配?是否要匹配第二个示例中的
特别幸运抽奖
如果是这样,很明显你不能使用边界……是的,你是对的,我已经观察到了这一点,现在我只想使用linq**Regex.Match(message,arrayofstring)。Success**Try
(?您能否回答第二部分?您可以使用LINQ进行多个测试-如果您只是在搜索匹配的子字符串,为什么要使用正则表达式?请使用注释的正确答案更新您的问题。
arrayOfStrings.Any(s=>message.Contains))