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

  • 相关阅读:
    MariaDB + Visual Studio 2017 环境下的 ODBC 入门开发
    CUDA 9.1/9.2 与 Visual Studio 2017 (VS2017 15.6.4) 的不兼容问题
    用 SDL2 在屏幕上打印文本
    用 SDL2 处理精灵图
    用 SDL2 进行事件驱动编程
    用 SDL2 加载PNG平铺背景并显示前景
    用 SDL2 平铺背景并显示前景
    用 SDL2 显示一张图片
    VPS 安全措施(CentOS 6)
    Hello World!
  • 原文地址:https://www.cnblogs.com/lcxdever/p/3738759.html
Copyright © 2011-2022 走看看