我有很多单词的清单.我需要的是找到以"ing","ed","ied"结尾的所有单词以及单个元音和加倍辅音之前:应该匹配单词:begged,slamming,zagging.不匹配帮助("lp" - 不是双辅音)
\w*[^aoyie][aoyie]([^aoyie])\1(ed|ing|ied)
Run Code Online (Sandbox Code Playgroud)
它正在使用RegexPal.com,但它不能在C#中工作(不匹配任何单词,在列表中返回0个单词)
我的代码:
List<Book_to_Word> allWords = (from f in db2.Book_to_Words.AsEnumerable() select f).ToList();
List<Book_to_Word> wordsNOTExist = (from f in allWords
where Regex.IsMatch(f.WordStr, @"^(\w*[^aoyie]+[aoyie]([^aoyie])(ed|ing|ied))$")
select f).ToList();
Run Code Online (Sandbox Code Playgroud)
当我不使用\ 1时工作.但是用单个辅音返回单词.
尽量放松一下这个条件:
@"^[a-z]*[aoyie]([^aoyie])\1(ed|ing|ied)$"
Run Code Online (Sandbox Code Playgroud)
您当前的正则表达式要求单词在双辅音和后缀之前至少有3个字符.所以"乞求"和"唠叨"是不匹配的.
但是,在组中看到"y"有点奇怪,而"u"缺失(例如"抢劫").你可能想要仔细检查一下.在"ied"之前我对双辅音有点怀疑,但我会把它留在那里.
感谢nhahtdh。问题出在括号外面。当我删除它们时,它起作用了:
Regex.IsMatch(f.WordStr, @"^\w*[^aoyieu]+[aoyieu]([^aoyieu])\1(ed|ing|ied)$")
Run Code Online (Sandbox Code Playgroud)