Android String to URL Convert extracURL(String _str)

Here you can find the source of extracURL(String _str)

Description

extrac URL

License

Apache License

Declaration

public static String extracURL(String _str) 

Method Source Code

//package com.java2s;
//License from project: Apache License 

import java.util.regex.Matcher;
import java.util.regex.Pattern;

import android.text.TextUtils;

public class Main {
    public static String extracURL(String _str) {

        if (TextUtils.isEmpty(_str))
            return "";

        // Tip: add a space to the end of original string
        String str = _str.trim() + " ";

        // javascript && file: not allowed
        if (str.matches("^\\w+script:") || str.matches("^file:\\/\\/\\/.+"))
            return "";

        Pattern regex = Pattern.compile("(https?://.+?)[\\s'\"<>\\[\\]]");
        Matcher matcher = regex.matcher(str);
        if (matcher.find()) {
            return matcher.group(1);
        } else {//from   www  .ja v a2 s  .  c  o m
            return "";
        }
    }
}

Related

  1. isUrl(String s)
  2. isUrl(String str)
  3. isUrl(String s)
  4. isUrlValid(String str)