Java 从字符串中提取子字符串
我有这样的字符串:Java 从字符串中提取子字符串,java,android,Java,Android,我有这样的字符串: <a hidden="true" href="xxx" class=" zt-uie-session </a> 您可以使用它来查找href值: href=“([^”]*)” 尝试下面的代码,它工作正常 String str = "<a hidden=\"true\" href=\"xxx\" class=\" zt-uie-session></a>"; Matcher m = Patte
<a hidden="true" href="xxx" class=" zt-uie-session </a>
您可以使用它来查找href值:
href=“([^”]*)”
尝试下面的代码,它工作正常
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"
}
String str=”“;
Matcher m=Pattern.compile(“(?:href)=\”([^\“]+)”).Matcher(str);
while(m.find()){
字符串结果=m.group(1);
Log.d(“HREF”,:“+result);//结果为“xxx”
}
您可以使用Jsoup库轻松提取html属性
Document doc = Jsoup.parse("<a href='link' />");
Element link = doc.select("a").first();
return link.attr("href"); //xxx
Document doc=Jsoup.parse(“indexOf and substringIshidden
andclass
总是会出现吗?只显示一个字符串是不够的。请给出更多示例,说明字符串可以如何更改,字符串的格式是什么。请不要使用任何类型的字符串
功能性。如果此标记没有像您的问题中那样格式错误,请使用u东南方
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"
}
Document doc = Jsoup.parse("<a href='link' />");
Element link = doc.select("a").first();
return link.attr("href"); //xxx