I need to capture the third instance of a pattern using regex. My code works using the online R Regex Tester, but not with the stringr::str_extract() function.
What is the reason for this?
string = c("W901 Z846 W903 Z846 W919 Z846 Z941")
str_extract(string, "^(?:.*?Z84[1-9]{1}){2}(.*?Z84[1-9]{1})")
# [1] "W901 Z846 W903 Z846 W919 Z846"
Result should be: "W919 Z846".
See this R Regex Tester result where the correct result is returned.
strcapturein base R:strcapture(pat, string, list(x = character()))