List of utility methods to do String to URL Convert
String | extracURL(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()) { ... |
boolean | isUrl(String s) is Url if (s == null) { return false; return Pattern.matches(URL_REG_EXPRESSION, s); |
boolean | isUrl(String str) is Url if (str == null) { return false; if (str.startsWith("http")) { return true; return false; |
boolean | isUrl(String s) is Url if (s == null) { return false; return Pattern.matches(URL_REG_EXPRESSION, s); |
boolean | isUrlValid(String str) Check if give string is a valid url return isUrlValid(str, CASE_NON_SENSITIVE);
|
boolean | isHttpUrl(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; |
String | getDomain(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) { ... |
StringBuffer | findUrl(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>"); ... |
boolean | isImageUrl(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(); |
String | getBaseUrl(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; |