java正则判断某字符串是否为网址

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/LucasXu01/article/details/82955024
​
 /**
     * 判断字符串是否为URL
     * @param urls 需要判断的String类型url
     * @return true:是URL;false:不是URL
     */
    public static boolean isHttpUrl(String urls) {
        boolean isurl = false;
        String regex = "(((https|http)?://)?([a-z0-9]+[.])|(www.))"
            + "\\w+[.|\\/]([a-z0-9]{0,})?[[.]([a-z0-9]{0,})]+((/[\\S&&[^,;\u4E00-\u9FA5]]+)+)?([.][a-z0-9]{0,}+|/?)";//设置正则表达式

        Pattern pat = Pattern.compile(regex.trim());//对比
        Matcher mat = pat.matcher(urls.trim());
        isurl = mat.matches();//判断是否匹配
        if (isurl) {
            isurl = true;
        }
        return isurl;
    }


​

猜你喜欢

转载自blog.csdn.net/LucasXu01/article/details/82955024