正则表达式(三)——java中的应用

来源:互联网 发布:2016淘宝刷单不降权 编辑:程序博客网 时间:2024/09/21 09:23

可用对象:        

      regex包 和String中的 replaceAll split 函数支持正则表达式

      Matcher中的matches从头开始匹配, lookingAt从指定除开始  find:从序列的任意处开始

 

常用函数:

         String.split  : 使用正则表达式拆分字符串

         String.matches:  字符串是否匹配给定的正则表达式,返回rue|false

         String.replaceAll

         String.replaceFirst: 替换

实例:

      
        Pattern p = Pattern.compile("a*b");        Matcher m = p.matcher("aaaaab");        boolean b = m.matches();  //是否匹配                      while(m.find()){            Stringg = m.group();           //System.out.println(g);            dist =g;        }   //查找


 


原创粉丝点击