Regex.Match double consonants in C #

I have a list of many words. I need to find all words ending in "ing", "ed", "ied" and with one vowel and double consonant before: Must match the words: ask, clap, tie. Not relevant help ("lp" -not double consonant)

\w*[^aoyie][aoyie]([^aoyie])\1(ed|ing|ied) 

It works on RegexPal.com, but it does not work in C # (does not match any words, returns 0 words in the list)

My code is:

 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(); 

It works when I do not use \ 1. But returns words with one consonant.

+6
source share
2 answers

Thanks nhahtdh. The problem was in the outer brackets. When I deleted them, it worked:

 Regex.IsMatch(f.WordStr, @"^\w*[^aoyieu]+[aoyieu]([^aoyieu])\1(ed|ing|ied)$") 
0
source

Try relaxing the condition a bit:

 @"^[az]*[aoyie]([^aoyie])\1(ed|ing|ied)$" 

Your current regular expression will require the word to have at least 3 characters before the double consonant and the suffix. Therefore, "begging" and "jam" do not match.

It is a little strange, however, to see "y" in the group, while "u" is absent (for example, "mugged"). You probably want to double check this. And I have little doubt about the double consonant before ied, but I will leave it there.

+6
source

Source: https://habr.com/ru/post/919109/


All Articles