I am working with Data Mining and regular expressions. I want to select certain strings from a text ("text_strings) with the grep() function. I want R to do the following: Select all the strings that have words with exactly two "a", the "a" don't have to be necessarily consecutive, or exactly two "s". I tried the function grep("a{2}|s{2}"), text_strings, value = TRUE). The problem is that with this function R only shows me strings with words that contain consecutive "a" and "s". I would be very thankful if someone could help me solve this!
You just need to check for anything between your a/s:
s <- c('qwer', 'asdf', 'dafsf', 'asdfa', 'asdfas', 'qaaq', 'qssq')
grep('a.*a|s.*s', s)
#> [1] 4 5 6 7