I'm trying to retrieve information from a text file that contains tags, e.g.:
<name> Joe </name>
The text file consists of multiple lines some with more of these tags (e.g. for height and weight) and some with just other text. I refer to the text file as "sheet" (see code below).
I would like to retrieve the text between the tags. I have come up with the following solution to do so:
m1 <- regexpr("<name> [a-zA-Z]+ </name>", sheet)
m2 <- regmatches(sheet,m1)
m3 <- gsub("<name> ", "", gsub(" </name>", "", m2))
m3
I have not worked with regular expressions before, but I was wondering whether I am not taking a detour with my 'regmatches'. It seems there should be a more direct way to retrieve text inside tags?
Thanks,
Richard