• 几个可以用到的正则表达式


    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

  • 相关阅读:
    MongoDB解析 2XML配置文件
    MongoDB解析 1理论基础
    JAVA GoF设计模式6大设计原则
    Kafka解析1快速入门
    JAVA GoF设计模式 1创建型设计模式
    B/S架构与C/S架构的区别
    【笔记】Oracle使用笔记
    如何通过WinDbg获取方法参数值
    Windows 启动过程
    ubuntu安装leveldb
  • 原文地址:https://www.cnblogs.com/lcxdever/p/3738759.html
Copyright © 2020-2023  润新知