Let's say I want to find all words in which letter "e" appears exactly two times. When I define this pattern:
pattern1 <- "e.*e"
grep(pattern1, stringr::words, value = T)
RegEx also matches words such as "therefore", because "e" appears (at least) two times as well. The point is, I don't want my pattern to be "at least", I want it to be "exactly n times".
This pattern...
pattern2 <- "e{2}"
...finds words with two letter "e", but only if they appear one after each other ("feel", "agre" etc). I'd like to combines these two patterns to find all words with exact number of not necessarily consecutive appearances of a letter "e".
See Question&Answers more detail:os