Reputation: 493
I have string like this:
<a hidden="true" href="xxx" class=" zt-uie-session </a>
How to extract href value in Android? It's string, not some object.
Upvotes: 1
Views: 201
Reputation: 9117
you can use Jsoup library for easily extract html attributes
Document doc = Jsoup.parse("<a href='link' />");
Element link = doc.select("a").first();
return link.attr("href"); //xxx
Doc here
Upvotes: 0
Reputation: 1909
Try below code it is working fine
String str = "<a hidden=\"true\" href=\"xxx\" class=\" zt-uie-session></a>";
Matcher m = Pattern.compile(" (?:href)=\"([^\"]+)").matcher(str);
while (m.find()) {
String result = m.group(1);
Log.d("HREF",": "+result); //result is "xxx"
}
Upvotes: 0
Reputation: 31841
You can use this regex to find href value:
href="([^"]*)"
Matcher m = Pattern.compile("href=\"([^\"]*)\"").matcher("<a hidden=\"true\" href=\"xxx\" class=\" zt-uie-session </a>");
if (m.find())
System.out.println(m.group(1));
Output
xxx
Upvotes: 2