Skip to main content
 首页 » 编程设计

c#之简化多个 Or Regex 查询

2024年02月05日9pander-it

我需要检测当前文本是否包含以下关键字“guest post”、“guest post”、“guest contributor”、“guest-etc”。

我可以像下面这样写查询。

"guest.?post|guest.?write|guest.?contributor|guest.?etc" 

我正在寻找一种方法来缩短此正则表达式查询。

请您参考如下方法:

将公共(public)前缀放在组外,将备选前缀放在组内。

guest.?(?:post|write|contributor|etc)