zoukankan      html  css  js  c++  java
  • 正则表达式的规则

    A:字符类

    * [abc] a、b 或 c(简单类)

    * [^abc] 任何字符,除了 a、b 或 c(否定)

    * [a-zA-Z] a到 z 或 A到 Z,两头的字母包括在内(范围)

    * [0-9] 0到9的字符都包括

    B:预定义字符类

    * . 任何字符。

    * d 数字:[0-9]

    * w 单词字符:[a-zA-Z_0-9]

    C:Greedy 数量词

    * X? X,一次或一次也没有

    * X* X,零次或多次

    * X+ X,一次或多次

    * X{n} X,恰好 n 次

    * X{n,} X,至少 n 次

    * X{n,m} X,至少 n 次,但是不超过 m 次


    package com.loaderman.regex;
    
     
    public class Demo_Regex {
       /**
    
        * Greedy 数量词 
    
          X? X,一次或一次也没有 
    
          X* X,零次或多次 
    
          X+ X,一次或多次 
    
          X{n} X,恰好 n 次 
    
          X{n,} X,至少 n 次 
    
          X{n,m} X,至少 n 次,但是不超过 m 次 
    
        */
       public static void main(String[] args) {
    
          //demo1();
    
          //demo2();
    
          //demo3();
    
          //demo4();
    
          //demo5();
    
          String regex = "[abc]{5,15}";
    
          System.out.println("abcba".matches(regex));
    
          System.out.println("abcbaabcabbabab".matches(regex));
    
          System.out.println("abcb".matches(regex));
    
          System.out.println("abcbaabaabcbaaba".matches(regex));
    
       }
       public static void demo5() {
    
          String regex = "[abc]{5,}";
    
          System.out.println("abcba".matches(regex));
    
          System.out.println("abcbaabcabbabab".matches(regex));
    
          System.out.println("abcb".matches(regex));
    
          System.out.println("abcbaaba".matches(regex));
    
       }
       public static void demo4() {
    
          String regex = "[abc]{5}";
    
          System.out.println("abcba".matches(regex));
    
          System.out.println("abcbaabcabbabab".matches(regex));
    
          System.out.println("abcb".matches(regex));
    
          System.out.println("abcbaaba".matches(regex));
    
       }
       public static void demo3() {
    
          String regex = "[abc]+";
    
          System.out.println("".matches(regex));
    
          System.out.println("a".matches(regex));
    
          System.out.println("aaaaabbbbccccc".matches(regex));
    
       }
       public static void demo2() {
    
          String regex = "[abc]*";
    
          System.out.println("".matches(regex));
    
          System.out.println("abc".matches(regex));
    
          System.out.println("a".matches(regex));
    
       }
       public static void demo1() {
    
          String regex = "[abc]?";
    
          System.out.println("a".matches(regex));
    
          System.out.println("b".matches(regex));
    
          System.out.println("c".matches(regex));
    
          System.out.println("d".matches(regex));
    
          System.out.println("".matches(regex));
    
       }
    }
    
  • 相关阅读:
    算法之字符串
    linux环境无界面运行selenium
    用猴子补丁的方式解决 python unittest按定义的顺序执行用例
    adb命令行执行uiautomator2
    uiautomator2环境搭建
    jenkins安装
    python unittest自动化数据驱动demo
    uiautomator1与2的区别
    HttpRunnerManager学习
    接口测试
  • 原文地址:https://www.cnblogs.com/loaderman/p/6407295.html
Copyright © 2011-2022 走看看