As an amendment / note to LyzandeRs, answer here a version that does not use the dplyr dictionary, only the magrittr pipe. Therefore, writing shell functions and specifying arguments, etc. May be skipped.
This is a bit more verbose than dplyr . But it is less detailed than base and allows you to use the full flexibility of any function, such as grep or stringi::stri_detect , etc.
And it is much faster. Check below benchmarks. Of course, it should be noted that the speed should be checked for larger examples, the dplyr overhead is large enough for this small example, therefore, a fair comparison of the speed depends on the use case.
df <- data.frame(baa=0,boo=0,boa=0,lol=0,bAa=0) library(magrittr) df %>% .[,grep("(?i)b(?!a)", names(.), perl = T)]
source share