I found the provisions of "oo" in the following sentence:
sentence <- "It is a good book. Good for first reading. This book explains everything in Qdetail with tons of examples and exercises for practice. Good for cracking written tests on campuses and competitive exams. It is cheap so any way one can have a copy along with other books" pos = gregexpr("oo", sentence)
I got the result as
> pos [[1]] [1] 10 15 21 50 136 263 attr(,"match.length") [1] 2 2 2 2 2 2 attr(,"useBytes") [1] TRUE
Based on the result, I want to extract 10 characters from each position (5 to position and 5 after position)
For example, I have to get the result for the first location, because "good bo" And I want this booty for each position. Since I am new to R, I could not figure out how to do this. Please help me with this.
What if I need to extract the words as shown below: I have to get a โgood bookโ for the first copy of the match
source share