How would I “find” and “get” a value between two strings?
ie: <a>3</a>
I’m reading a file to find the location of <a>, where that starts, then it will stop reading when it finds </a> The value I want to return is “3”.
Using JRE 6
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.
Your two main options are:
1) preferred but potentially complicated: using an XML/HTML parser and getting the text within the first “a” element. e.g. using Jsoup (thanks @alpha123):
2) easier but not very reliable: using a regular expression to extract the characters between the
<a>and</a>strings. e.g.: