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

regex for phrase searching

我必须在大字符串中搜索短语,长度可能为 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(phrase one|phrase two|phrase three|etc)\b 的大型正则表达式,然后使用该正则表达式来匹配您的字符串。