Android Utililty Methods String to URL Convert

List of utility methods to do String to URL Convert

Description

The list of methods to do String to URL Convert are organized into topic(s).

Method

StringextracURL(String _str)
extrac URL
if (TextUtils.isEmpty(_str))
    return "";
String str = _str.trim() + " ";
if (str.matches("^\\w+script:") || str.matches("^file:\\/\\/\\/.+"))
    return "";
Pattern regex = Pattern.compile("(https?://.+?)[\\s'\"<>\\[\\]]");
Matcher matcher = regex.matcher(str);
if (matcher.find()) {
...
booleanisUrl(String s)
is Url
if (s == null) {
    return false;
return Pattern.matches(URL_REG_EXPRESSION, s);
booleanisUrl(String str)
is Url
if (str == null) {
    return false;
if (str.startsWith("http")) {
    return true;
return false;
booleanisUrl(String s)
is Url
if (s == null) {
    return false;
return Pattern.matches(URL_REG_EXPRESSION, s);
booleanisUrlValid(String str)
Check if give string is a valid url
return isUrlValid(str, CASE_NON_SENSITIVE);
booleanisHttpUrl(String input)
is Http Url
if (!isNullOrEmpty(input)) {
    String regexExpression = "http://([\\w\\WW-]+\\.)+[\\w\\W-]+(/[\\w\\W- ./?%&=]*)?";
    if (input.matches(regexExpression)) {
        return true;
return false;
StringgetDomain(String url)
get Domain
if (isEmptyOrNull(url))
    return null;
String domain;
try {
    int pos = url.indexOf("//");
    domain = url.substring(pos + 2);
    int endpos = domain.indexOf("/");
    if (url.indexOf("http") > -1) {
...
StringBufferfindUrl(StringBuilder sb)
find Url
Pattern pattern = Pattern
        .compile("(http://|https://){1}[\\w\\.\\-/:]+");
Matcher matcher = pattern.matcher(sb);
StringBuffer buffer = new StringBuffer();
while (matcher.find()) {
    String s = matcher.group(1);
    matcher.appendReplacement(buffer, "<a href=\"" + s + "\">" + s
            + "</a>");
...
booleanisImageUrl(String imgUrl)
is Image Url
if (isEmptyOrNull(imgUrl)) {
    return false;
String regEx = "([^\\s]+(\\.(?i)(jpg|png|gif))$)";
Pattern pattern = Pattern.compile(regEx);
Matcher matcher = pattern.matcher(imgUrl);
return matcher.matches();
StringgetBaseUrl(String pageUrl)
get Base Url
try {
    if (!pageUrl.contains("://")) {
        pageUrl = "http://" + pageUrl;
    int end = pageUrl.indexOf("/", pageUrl.indexOf("://") + 4);
    return pageUrl.substring(0, end);
} catch (Exception e) {
return null;