I have a text document and I'm trying to get the text between the words "abstract" and "keywords" (in R). This is the code I'm using:
gsub(".*abstract\\s*|keywords.*", "\\1", string)
However, this didn't work because somewhere else in the text the word "abstract" occurred so I made it non-greedy like this (added ? in front of abstract)
gsub(".*?abstract\\s*|keywords.*", "\\1", string)
But for some reason it now takes the text between "abstract" and "keywords" (which is what I want), but ALSO the text starting from the second "abstract" appearing in the text, all the way to the end. Any ideas?