How to grep data item from this html string
a <- "<div class=\"tst-10\">100%</div>"
so that the result is 100%? The main idea is to get data between > <.
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
I would use
gsub()in this case:Basically, this breaks the string up into three parts, each separated by regular brackets
(and). We can then use these as backreferences. The contents matched by the first set of backreferences can be referred to as\1(use a double slash to escape the special character), those matched in the second,\2and so on.So, essentially, we’re saying parse this string, figure out what matches my conditions, and return only the second backreference.
Piece by piece:
<.*>says to look for a “<” followed by any number of any characters “.*” up until you get to a “>”.*means to match any number of characters (up until the next condition)Keeping this in mind, you could actually probably use
gsub("(.*>)(.*)(<.*)", "\\2", a)and get the same result.