JavaSE---java.util---regex

时间:2020-10-18 16:32:26   收藏:0   阅读:21

1、Pattern

    A compiled representation of a regular expression.(一个正则表达式 编译表示

    无公共构造参数,可以通过static方法compile()创建实例

 

Pattern pattern = Pattern.compile("a");

 

 

2、Matcher

    An engine that performs match operations on a {@linkplain java.lang.CharSequence* character sequence} by interpreting a Pattern.(对输入字符串   进行解释和匹配操作的引擎

    无公共构造方法,需要调用 Pattern 对象的 matcher 方法来获得一个 Matcher 对象

 

Matcher matcher = pattern.matcher("cca");

 

     方法:

      public boolean find()    Attempts to find the next subsequence of the input sequence that matches the pattern.(找到匹配正则的字符)

      public Matcher appendReplacement(StringBuffer sb, String replacement)  将匹配正则的字符 用目标字符进行替换

 

评论(0
© 2014 mamicode.com 版权所有 京ICP备13008772号-2  联系我们:gaon5@hotmail.com
迷上了代码!