I have a list of many words. What I need is to find all words ending on "ing", "ed","ied" and with a single vowel and doubled consonant before: Should match words: begged, slamming, zagging. Not match helping ("lp"-not double consonant)
\w*[^aoyie][aoyie]([^aoyie])\1(ed|ing|ied)
It's working on RegexPal.com, but it is not working in C# (not matches any words, returns 0 words in list)
My code:
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();
Works when I don't use \1. But returns words with single consonant.
Most characters, including all letters ( a-z and A-Z ) and digits ( 0-9 ), match itself. For example, the regex x matches substring "x" ; z matches "z" ; and 9 matches "9" . Non-alphanumeric characters without special meaning in regex also matches itself. For example, = matches "=" ; @ matches "@" .
(?= regex_here) is a positive lookahead. It is a zero-width assertion, meaning that it matches a location that is followed by the regex contained within (?=
From the . NET documentation of Regex , \d matches any decimal digit. The signification of a "decimal digit" depends on the options of the regex: Without RegexOptions. ECMAScript (default): \d means \p{Nd} , e.g. any character from the Unicode category "Decimal digit"
The regular expression [A-Z][a-z]* matches any sequence of letters that starts with an uppercase letter and is followed by zero or more lowercase letters.
Try to relax the condition a bit:
@"^[a-z]*[aoyie]([^aoyie])\1(ed|ing|ied)$"
Your current regex will require the word to have at least 3 characters before the double consonant and the suffix. So "begged" and "zagging" are not matched.
It is a bit weird, though, to see "y" in the group, while "u" is missing (e.g. "mugged"). You probably want to double check about that. And I have a bit of doubt about double consonant before "ied", but I'll leave it there.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With