Reputation: 395
text = "the nurse was very helpful indeed"
I want to search for "very" and then extract "very" and one word after "very"
the output should be : very helpful
I used :
word(text, start = 4, end= 5 sep = fixed(" "))
The is helpful for extracting but I am unable to get the value dynamically for position of the word in the string which is "4" in this case
Upvotes: 2
Views: 2588
Reputation: 887971
We can use the str_extract
from stringr
library(stringr)
str_extract(text, "very\\s+\\w+")
Or with regexpr/regmatches
from base R
regmatches(text, regexpr("very\\s+\\w+", text))
Upvotes: 3