所需关键字的正则表达式?
我有一个 C# 系统,其中需要一组关键字。如果关键字存在,则必须检查两个字段。
最初,我编写了一个 foreach 循环来遍历每个关键字,然后循环结果并检查。但是,这有点低效,因为在检查时,我想查看给定字符串中是否存在任何关键字,而不是逐一查看。
谢谢。
I've got a system in C# where by a set of keywords are required. Two fields have to be checked if the keywords exist.
Initially I wrote a foreach loop to go through each keyword, then cycle through the results and check. However, this is somewhat inefficient, as on check, I would like to see if any of the keywords exist in a given string, rather than one by one.
Thanks.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
这个问题与您想要做的事情匹配吗?
答案向您展示如何使用正则表达式一次性匹配多个可能的单词
Does this question match what you are trying to do?
The answer shows you how to match multiple possible words in one go with a regex
((keyword1)|(keyword2)|(keyword3))
我不确定 c# 到底如何执行正则表达式,但这应该匹配并返回匹配项。
您可以在此处测试正则表达式
((keyword1)|(keyword2)|(keyword3))
Im not sure exactly how c# does regex but this should match and return matches.
You can test regexes here
如果你使用的是 c# 3.5+ 试试这个
If you are on c# 3.5+ try this