Regex with non-capturing group using stringr in R

Viewed 2638

I am trying to use non-capturing groups with the str_extract function from the stringr package. Here is an example:

library(stringr)
txt <- "foo"
str_extract(txt,"(?:f)(o+)")

This returns

"foo"

while i expect it to return only

"oo"

like in this post: https://stackoverflow.com/a/14244553/3750030

How do i use non-capturing groups in R to remove the content of the groups from the returned value while using it for matching?

1 Answers
Related