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 }

     

     

  • 相关阅读:
    详解Windows注册表分析取证
    逻辑漏洞简单的分析
    文件解析漏洞汇总
    aspcms 这个靶场。。。
    WebBug靶场基础篇 — 03
    WebBug靶场基础篇 — 02
    WebBug靶场介绍篇 — 01
    漏洞挖掘中的常见的源码泄露
    PHP对象Object的概念
    从史上八大MySQL事故中学到的经验
  • 原文地址:https://www.cnblogs.com/loritin/p/2725024.html
Copyright © 2011-2022 走看看