Search code examples
javaandroidhtmlregexhref

Android regular expression to get links of webpage source


I am looking for a RegEx to match links from a webpage source. If you have any code samples it would be appriciated.

Thanks


Solution

  • To match href attribute values you can use the following method:

    final Pattern pattern = Pattern.compile("href=\"(.*+)\"");
    Matcher matcher = pattern.matcher(html);
    String link = null;
    while (matcher.find())
    {
        link = matcher.group(1);
        Log.i("my.regex", "Found link: " + link);
    }