zoukankan      html  css  js  c++  java
  • 几个可以用到的正则表达式

    package lbi.flow.util;
    
    import net.sf.json.regexp.RegexpMatcher;
    
    public class RegexpUtils {
        /**
         * 匹配7c:d1:c3:73:d6:72形式mac
         * 
         * @return
         */
        public static RegexpMatcher getMacMatcher() {
            return net.sf.json.regexp.RegexpUtils
                    .getMatcher("[0-9a-f][0-9a-f]:[0-9a-f][0-9a-f]:[0-9a-f][0-9a-f]:[0-9a-f][0-9a-f]:[0-9a-f][0-9a-f]:[0-9a-f][0-9a-f]");
        }
    
        /**
         * 匹配20140430235959形式日期
         * 
         * @return
         */
        public static RegexpMatcher getTimeMatcher() {
            return net.sf.json.regexp.RegexpUtils
                    .getMatcher("^(?:(?!0000)[0-9]{4}(?:(?:0[1-9]|1[0-2])(?:0[1-9]|1[0-9]|2[0-8])|(?:0[13-9]|1[0-2])(?:29|30)|(?:0[13578]|1[02])-31)|(?:[0-9]{2}(?:0[48]|[2468][048]|[13579][26])|(?:0[48]|[2468][048]|[13579][26])00)-02-29)([01][0-9]|2[0-3])[0-5][0-9][0-5][0-9]$");
        }
    
        /**
         * 匹配2014-04-30 23:59:59形式日期
         * 
         * @return
         */
        public static RegexpMatcher getTimeMatcher2() {
            return net.sf.json.regexp.RegexpUtils
                    .getMatcher("^(?:(?!0000)[0-9]{4}-(?:(?:0[1-9]|1[0-2])-(?:0[1-9]|1[0-9]|2[0-8])|(?:0[13-9]|1[0-2])-(?:29|30)|(?:0[13578]|1[02])-31)|(?:[0-9]{2}(?:0[48]|[2468][048]|[13579][26])|(?:0[48]|[2468][048]|[13579][26])00)-02-29)\s+([01][0-9]|2[0-3]):[0-5][0-9]:[0-5][0-9]$");
        }
    
        /**
         * 匹配20140430形式日期
         * 
         * @return
         */
        public static RegexpMatcher getDateMatcher() {
            return net.sf.json.regexp.RegexpUtils
                    .getMatcher("^(?:(?!0000)[0-9]{4}(?:(?:0[1-9]|1[0-2])(?:0[1-9]|1[0-9]|2[0-8])|(?:0[13-9]|1[0-2])(?:29|30)|(?:0[13578]|1[02])-31)|(?:[0-9]{2}(?:0[48]|[2468][048]|[13579][26])|(?:0[48]|[2468][048]|[13579][26])00)-02-29)$");
        }
    
        /**
         * 匹配2014-04-30形式日期
         * 
         * @return
         */
        public static RegexpMatcher getDateMatcher2() {
            return net.sf.json.regexp.RegexpUtils
                    .getMatcher("^(?:(?!0000)[0-9]{4}-(?:(?:0[1-9]|1[0-2])-(?:0[1-9]|1[0-9]|2[0-8])|(?:0[13-9]|1[0-2])-(?:29|30)|(?:0[13578]|1[02])-31)|(?:[0-9]{2}(?:0[48]|[2468][048]|[13579][26])|(?:0[48]|[2468][048]|[13579][26])00)-02-29)$");
        }
    }

    工作时候正好用到了,顺便记录下来,以备后用。

    参考地址:http://blog.csdn.net/lxcnn/article/details/4362500

        http://www.cnblogs.com/deerchao/archive/2006/08/24/zhengzhe30fengzhongjiaocheng.html

  • 相关阅读:
    springboot入门系列(一):简单搭建springboot项目
    springboot入门系列(二):SpringBoot整合Swagger
    springboot入门系列(三):SpringBoot教程之RabbitMQ示例
    springboot入门系列(四):SpringBoot和Mybatis配置多数据源连接多个数据库
    Linux下安装RabbitMQ
    Mybatis原理之数据源和连接池
    springboot入门系列(五):SpringBoot连接多RabbitMQ源
    jsp中<c:foreach>分页标签的序号问题
    Java中删除一个文件夹下的所有文件(包括子目录内的文件)
    接口的幂等性
  • 原文地址:https://www.cnblogs.com/lcxdever/p/3738759.html
Copyright © 2011-2022 走看看