Java Code Examples for android.util.Patterns#WEB_URL

The following examples show how to use android.util.Patterns#WEB_URL . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: WebUtils.java    From SendBird-Android with MIT License 8 votes vote down vote up
/**
 * Extract urls from string.
 * @param input
 * @return
 */
public static List<String> extractUrls(String input)
{
    List<String> result = new ArrayList<String>();

    String[] words = input.split("\\s+");


    Pattern pattern = Patterns.WEB_URL;
    for(String word : words)
    {
        if(pattern.matcher(word).find())
        {
            if(!word.toLowerCase().contains("http://") && !word.toLowerCase().contains("https://"))
            {
                word = "http://" + word;
            }
            result.add(word);
        }
    }

    return result;
}
 
Example 2
Source File: WebUtils.java    From SendBird-Android with MIT License 6 votes vote down vote up
/**
 * Extract urls from string.
 * @param input
 * @return
 */
public static List<String> extractUrls(String input)
{
    List<String> result = new ArrayList<String>();

    String[] words = input.split("\\s+");


    Pattern pattern = Patterns.WEB_URL;
    for(String word : words)
    {
        if(pattern.matcher(word).find())
        {
            if(!word.toLowerCase().contains("http://") && !word.toLowerCase().contains("https://"))
            {
                word = "http://" + word;
            }
            result.add(word);
        }
    }

    return result;
}
 
Example 3
Source File: ValidatorUtils.java    From Cangol-appcore with Apache License 2.0 6 votes vote down vote up
/**
 * 验证web url地址格式是否正确
 *
 * @param str
 * @return
 */
public static boolean validateURL(String str) {
    if (str == null || "".equals(str)) {
        return false;
    }
    final Pattern p = Patterns.WEB_URL;
    final Matcher m = p.matcher(str);
    return m.matches();
}
 
Example 4
Source File: LinkUtils.java    From ChatMessagesAdapter-android with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
/**
 * Returns a list with all links contained in the input
 */
public static List<String> extractUrls(String text) {
    List<String> containedUrls = new ArrayList<>();
    Pattern pattern = Patterns.WEB_URL;
    Matcher urlMatcher = pattern.matcher(text);

    while (urlMatcher.find()) {
        containedUrls.add(text.substring(urlMatcher.start(0), urlMatcher.end(0)));
    }

    return containedUrls;
}
 
Example 5
Source File: Utils.java    From alpha-wallet-android with MIT License 4 votes vote down vote up
public static boolean isValidUrl(String url) {
    Pattern p = Patterns.WEB_URL;
    Matcher m = p.matcher(url.toLowerCase());
    return m.matches();
}