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, stri
We can use a pattern to match zero or more characters that are not 'e' ([^e]*) from the start (^) of the string, followed by character 'e', then another set of characters that are not 'e' followed by 'e', and zero or more characters not an 'e' until the end ($) of the string
res <- grep("^[^e]*e[^e]*e[^e]*$", stringr::words, value = TRUE)
stringr::str_count(res, "e")
#[1] 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2
#[58] 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2
#[115] 2 2 2 2 2 2 2