码迷,mamicode.com
首页 > 其他好文 > 详细

正则表达式 1

时间:2018-02-24 19:23:54      阅读:133      评论:0      收藏:0      [点我收藏+]

标签:ati   匹配   blog   pos   log   system   foo   nbsp   class   

package match;

public class TestOne {

    public static void main(String[] args) {

        //2015-10-19 08:00:00.0
        /*if ("0800000".matches("[0-9]{4,}") == false) {
            System.out.println(true);
        }else {
            System.out.println(false);
        }*/
        
        
    /*    if ("abc.2".matches("[a-z]{1,}[.][0-9]")) {
            System.out.println(true);
        }else {
            System.out.println(false);
        }*/
        
        
        
/*        /////                  +                 {m,n}:最少匹配m次,最多匹配n次
        if ("foo".matches("fo+")) {//匹配前面子表达式1次或多次 等价于 {1,}
            System.out.println(true);
        }else {
            System.out.println(false);
        }
        
        if ("foo".matches("fo{1,2}")) {
            System.out.println(true);
        }else {
            System.out.println(false);
        }
        
        
        /////                    ?                    {m,n}:最少匹配m次
        if ("does".matches("do(es)?")) {//匹配前面的子表达式0次或者1次,等价于 {0,1}
            System.out.println(true);
        }else {
            System.out.println(false);
        }
        
        if ("doeses".matches("do(es){0,2}")) {//匹配前面的子表达式0次或者1次,等价于 {0,1}
            System.out.println(true);
        }else {
            System.out.println(false);
        }
        
        /////////     *    匹配前面的字符任意次    等价于    {0,}
        
        */
        
        
/*        if ("a".matches("[abc]")) { //匹配 [] 集合中的字符
            System.out.println(true);
        }else {
            System.out.println(false);
        }
        
        if ("a".matches("[^abc]")) { //匹配不在 [] 集合中的字符
            System.out.println(true);
        }else {
            System.out.println(false);
        }*/
        
        
/*        ///////////////    | 
        if ("x".matches("x|y")) { //匹配x或者y
            System.out.println(true);
        }else {
            System.out.println(false);
        }
        
        if ("xoo".matches("[x|y]oo")) { //匹配x或者y
            System.out.println(true);
        }else {
            System.out.println(false);
        }
        */
        
        
    }

}

 

正则表达式 1

标签:ati   匹配   blog   pos   log   system   foo   nbsp   class   

原文地址:https://www.cnblogs.com/lxh520/p/8467175.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!