zoukankan      html  css  js  c++  java
  • 通过网址获取主域名

    /**
     * 域名中包含一级、二级域名等信息,需要提取根域名。
     * 例如:www.baidu.com 提取出 baidu.com
     * http://write.blog.csdn.net/ 提取出 csdn.net
     * @author liubing
     *
     */
    public class TopDomainUtil {
        private Pattern pattern;  
        private static Logger logger =LoggerFactory.getLogger(TopDomainUtil.class);
        // 定义正则表达式,域名的根需要自定义,
        private static final String RE_TOP = "[\w-]+\.(com.cn|net.cn|gov.cn|org\.nz|org.cn|com|net|org|gov|cc|biz|info|cn|co)\b()*";  
     
        // 构造函数  
        public TopDomainUtil() {  
            pattern = Pattern.compile(RE_TOP , Pattern.CASE_INSENSITIVE);  
        }  
        public String getTopDomain(String url) {  
            String result = url;  
            try {  
                Matcher matcher = this.pattern.matcher(url);  
                matcher.find();  
                result = matcher.group();  
            } catch (Exception e) {  
                logger.error("TopDomainUtil"+"未找到对应的主域名!");  
            }  
            return result;  
        }   
    }

  • 相关阅读:
    Matlab 基础
    C# 基础
    Linux Shell
    【Luogu3381】【模板】缩点
    KMP学习笔记
    品味题目的味道
    【NOI2015】【BZOJ4196】软件包管理器
    宝藏
    状态压缩动态规划
    第一篇随笔
  • 原文地址:https://www.cnblogs.com/bingru/p/7560533.html
Copyright © 2011-2022 走看看