Non-capturing group
To use parentheses without creating matching groups, you can create a non-capturing group with (?:)
.
x <- c("a gray cat", "a grey dog")
str_match(x, "gr(e|a)y")
## [,1] [,2]
## [1,] "gray" "a"
## [2,] "grey" "e"
str_match(x, "gr(?:e|a)y")
## [,1]
## [1,] "gray"
## [2,] "grey"