Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/377.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 从字符串中提取子字符串_Java_Android - Fatal编程技术网

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 substringIs
hidden
and
class
总是会出现吗?只显示一个字符串是不够的。请给出更多示例,说明字符串可以如何更改,字符串的格式是什么。请不要使用任何类型的
字符串
功能性。如果此标记没有像您的问题中那样格式错误,请使用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