zoukankan      html  css  js  c++  java
  • java正则表达式(四)

    四、非匹配

    在正则表达式中,我们往往需要在字符串中进行非匹配,这时,就要通过^进行匹配条件限制,^的常见入门用法如下:

    [^a-z]     条件限制在非小写a to z范围中一个字符
    [^A-Z]     条件限制在非大写A to Z范围中一个字符
    [^a-zA-Z] 条件限制在非小写a to z或大写A to Z范围中一个字符
    [^0-9]     条件限制在非0 to 9范围中一个字符
    [^0-9a-z] 条件限制在非0 to 9或a to z范围中一个字符

     

    代码示例如下:

     1 public class RegExp {
     2     private Pattern patt;
     3     private Matcher matcher;
     4 
     5   public boolean squareReg(String regStr,String regex){
     6         return this.commonRegExp(regStr, regex);
     7     }
     8 
     9   private boolean commonRegExp(String regStr,String regex){
    10         boolean wildcard_Res=false;
    11         patt=Pattern.compile(regex);
    12         matcher=patt.matcher(regStr);
    13         wildcard_Res= matcher.find();
    14         return wildcard_Res;
    15     }
    16 }
    17 
    18 public class TestRegExp {
    19     public static void main(String[] args) {
    20         RegExp re=new RegExp();
    21         boolean wildcard_Res=false;
    22 
    23      wildcard_Res=re.squareReg("tcn", "t[^aoe]n");
    24      System.out.println(wildcard_Res);
    25         //输出:wildcard_Res=true
    26 }

     

     

  • 相关阅读:
    Spring Cloud概述
    Servlet调用流程和Spring MVC调用流程
    待看文章链接
    MyBatis之 resultMap 元素子元素详解
    MyBatis核心配置文件模板代码
    ios上架
    iOS打包部署
    Android XML绘图(4)——Bitmap
    Android XML绘图(2)——Layer
    Android XML绘图(3)——Selector
  • 原文地址:https://www.cnblogs.com/loritin/p/2725024.html
Copyright © 2011-2022 走看看