匹配在C#中使用正则表达式复数 [英] Matching plurals using regex in C#
本文介绍了匹配在C#中使用正则表达式复数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我期待使用正则表达式在C#中搜索方面,我想在搜索中包含这些词的复数。例如,如果用户想搜索'管',那么我想为'管道',以及返回结果。
I'm looking to use regex in C# to search for terms and I want to include the plurals of those terms in the search. For example if the user wants to search for 'pipe' then I want to return results for 'pipes' as well.
因此,我可以做到这一点...
So I can do this...
string s ="\\b" + term + "s*\\b";
if (Regex.IsMatch(bigtext, s) { /* do stuff */ }
我将如何修改上面让我来搭配,比如,'讲'当用户输入'压力'和'管'/'管道'仍然有效?
How would I modify the above to allow me to match, say, 'stresses' when the user enters 'stress' and still work for 'pipe'/'pipes'?
推荐答案
下面是创建去除复数一个正则表达式:
Here's a regex created to remove the plurals:
/(?<![aei])([ie][d])(?=[^a-zA-Z])|(?<=[ertkgwmnl])s(?=[^a-zA-Z])/g
(演示和放大器;源)
我知道这不是正是你需要的,但它可能会帮助你找到的东西了。
I know it's not exactly what you need, but it may help you find something out.
这篇关于匹配在C#中使用正则表达式复数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文