zoukankan      html  css  js  c++  java
  • 正则表达式中Matcher上的4个方法

    boolean matches()
    boolean lookingAt()
    boolean find()
    boolean find(int start)
    
    • matches()方法用来判断整个输入字符串是否匹配正则表达式模式
    • lookingAt()用来判断该字符串(不必是整个字符串)的起始部分是否能够匹配模式
    • find()用来在CharSequence中查找多个匹配。
    //: strings/Finding.java
    import java.util.regex.*;
    import static net.mindview.util.Print.*;
    
    public class Finding {
      public static void main(String[] args) {
        Matcher m = Pattern.compile("\w+")
          .matcher("Evening is full of the linnet's wings");
        while(m.find())
          printnb(m.group() + " ");
        print();
        int i = 0;
        while(m.find(i)) {
          printnb(m.group() + " ");
          i++;
        }
      }
    } /* Output:
    Evening is full of the linnet s wings
    Evening vening ening ning ing ng g is is s full full ull ll l of of f the the he e linnet linnet innet nnet net et t s s wings wings ings ngs gs s
    *///:~
    

    find()像迭代器那样遍历输入的字符串,而第二个带参的find(int start)则是接受一个参数,该参数表示字符串中字符的位置,并以其为搜索的起点。

  • 相关阅读:
    git
    rocketMq
    mysql 擎特点
    mysql 主从复制实现步骤
    mysql数据库服务日志
    mysql 主命令总结
    linux sed
    学习进步的方法
    my-innodb-heavy-4g.cnf
    FTP主动模式和被动模式的区别【转】
  • 原文地址:https://www.cnblogs.com/fanlumaster/p/13681705.html
Copyright © 2011-2022 走看看