Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/194.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
Android解析html保存href链接_Android_Html_Parsing_Hyperlink_Href - Fatal编程技术网

Android解析html保存href链接

Android解析html保存href链接,android,html,parsing,hyperlink,href,Android,Html,Parsing,Hyperlink,Href,我有一个html字符串,如: 其中一个环节是 如何将此html字符串转换为包含链接但不包含任何html标记的字符串: 结果应该是: 一个链接是String regex=“^(https?| ftp |文件)://[-a-zA-Z0-9+&@#/%?=~ |!:,.;]*[-a-zA-Z0-9+&@#/%=~ |]; String regex=“\\b(https?| ftp |文件)://[-a-zA-Z0-9+&@#/%?=~|!:,.;]*[-a-zA-Z0-9+&@#/%=~|]”; 字符

我有一个html字符串,如:

其中一个环节是

如何将此html字符串转换为包含链接但不包含任何html标记的字符串: 结果应该是:

一个链接是

String regex=“^(https?| ftp |文件)://[-a-zA-Z0-9+&@#/%?=~ |!:,.;]*[-a-zA-Z0-9+&@#/%=~ |];
String regex=“\\b(https?| ftp |文件)://[-a-zA-Z0-9+&@#/%?=~|!:,.;]*[-a-zA-Z0-9+&@#/%=~|]”;
字符串regex=“”;//比赛
字符串regex=“”;//不匹配

您将获得类似以下内容的字符串

One link is <a href="http://image.html">sajfhds iufl</a>
一个链接是
你需要的是

One link is <a href="http://image.html">http://image.html</a>
一个链接是
所以,您应该使用下面的代码查找模式

//imports required
import java.util.regex.Matcher;
import java.util.regex.Pattern;

        String stringToSearch = "<a href = \"http://image.html\" > sajfhds iufl</a>";

        // the pattern we want to search for
        Pattern p = Pattern.compile("<a href\\s*=\\s*\"(.+?)\"\\s*>(.+?)</a>");
        Matcher m = p.matcher(stringToSearch);

        if (m.find())
        {
          String temp = stringToSearch.replace(m.group(2), m.group(1)); 
          //use the temp string for display
        }
//需要导入
导入java.util.regex.Matcher;
导入java.util.regex.Pattern;
字符串stringToSearch=“”;
//我们要搜索的模式
Pattern p=Pattern.compile(“”);
匹配器m=p.Matcher(stringToSearch);
if(m.find())
{
字符串温度=字符串搜索替换(m组(2),m组(1));
//使用临时字符串进行显示
}
//imports required
import java.util.regex.Matcher;
import java.util.regex.Pattern;

        String stringToSearch = "<a href = \"http://image.html\" > sajfhds iufl</a>";

        // the pattern we want to search for
        Pattern p = Pattern.compile("<a href\\s*=\\s*\"(.+?)\"\\s*>(.+?)</a>");
        Matcher m = p.matcher(stringToSearch);

        if (m.find())
        {
          String temp = stringToSearch.replace(m.group(2), m.group(1)); 
          //use the temp string for display
        }