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

Usm*_*sif 3 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 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;
Run Code Online (Sandbox Code Playgroud)

我正在执行上述解决方法,但它不能满足所有情况。

当我有多个短语时我必须做什么,我想linq在这种情况下使用,例如:

bool success = Regex.Match(message,  **arrayofstrings**).Success;
Run Code Online (Sandbox Code Playgroud)

blh*_*ing 6

您可以使用循环\b(phrase one|phrase two|phrase three|etc)\b从短语数组中构建一个大型正则表达式,然后使用该正则表达式来匹配您的字符串。