5.1 Test for a Match1
The simplest patterns match exact strings:
x <- c("apple", "banana", "pear")
str_extract(x, "an")
## [1] NA "an" NA
This syntax is case sensitive:
bananas <- c("banana", "Banana", "BANANA")
str_detect(bananas, "banana")
## [1] TRUE FALSE FALSE
str_detect(bananas, regex("banana", ignore_case = TRUE))
## [1] TRUE TRUE TRUE
The next step up in complexity is ., which matches any character except a newline:
str_extract(x, ".a.")
## [1] NA "ban" "ear"
You can allow . to match everything, including \n, by setting dotall = TRUE: ...