zoukankan      html  css  js  c++  java
  • java-正则表达式2

    package com.day10.Regex正则表达式;

    public class Demo2Regex {

      /**
      * A:字符类
      *    [abc] a、b 或 c(简单类)
      *    [^abc] 任何字符,除了 a、b 或 c(否定)
      *    [a-zA-Z] a到 z 或 A到 Z,两头的字母包括在内(范围)
      *    [a-d[m-p]] a到d或m到p:[a-dm-p](并集)
      *    [a-z&&[def]]d、e或f(交集),相当于是def
      *    [a-z&&[^bc]]a到z,除了b和c:[ad-z](减去)
      *    [a-z&&[^m-p]]a到z,而非m到p:[a-lq-z](减去)
      *    [0-9] 0到9的字符都包括
      */
      public static void main(String[] args) {
        String regex="[abc]";//[]代表单个字符
        System.out.println("a".matches(regex));//true
        System.out.println("b".matches(regex));//true
        System.out.println("c".matches(regex));//true
        System.out.println("d".matches(regex));//false
        System.out.println("%".matches(regex));//false

        String regex1="[^abc]";
        System.out.println("a".matches(regex1));//fasle
        System.out.println("b".matches(regex1));//false
        System.out.println("c".matches(regex1));//false
        System.out.println("d".matches(regex1));//true
        System.out.println("%".matches(regex1));//true
        System.out.println("10".matches(regex1));//false,中括号代表单个字符,10是两个字符

        String regex2="[a-zA-Z]";
        System.out.println("a".matches(regex2));//true
        System.out.println("A".matches(regex2));//true
        System.out.println("z".matches(regex2));//true
        System.out.println("Z".matches(regex2));//true
        System.out.println("%".matches(regex2));//false
      }

    }

  • 相关阅读:
    页面上输入任意数字,点击按钮后计算阶乘。
    利用递归求两个数字的最大公约数。
    17css动画
    10Vue组件参数校验和非Props特性
    git rebase --continue出现“If there is nothing left to stage,chances are that something else already introduced the same changes; you might want to skip this patch.”
    9Vue父子组件的传递方式
    8Vue组件使用细节
    Block-scoped declarations问题解决
    7Vue中的set方法
    6Vue条件渲染
  • 原文地址:https://www.cnblogs.com/zhujialei123/p/8179321.html
Copyright © 2011-2022 走看看