I'm trying to extract the n
th word from strings and found several links that suggest a method that doesn't seem to work in R.
myString <- "HANS CHRISTIAN ANDERSON III"
str_extract(myString,'(?:\\S+ ){1}(\\S+)')
# [1] "HANS CHRISTIAN"
str_extract(myString,'(?:\\S+ ){2}(\\S+)')
# [1] "HANS CHRISTIAN ANDERSON"
As you can see, my commands are returning both the non-capturing and capturing group. What's the solution to get only the specific n
th word?