java.util.regex.Matcher.reset()方法重置此匹配器。
Matcher reset() - 声明
public Matcher reset()
Matcher reset() - 示例
下面的示例显示java.util.regex.Matcher.reset()方法的用法。
package com.learnfk; import java.util.regex.Matcher; import java.util.regex.Pattern; public class MatcherDemo { private static String REGEX = "(a*b)(foo)"; private static String INPUT = "aabfooaabfooabfoob"; private static String REPLACE = "-"; public static void main(String[] args) { Pattern pattern = Pattern.compile(REGEX); //获取匹配器对象 Matcher matcher = pattern.matcher(INPUT); matcher.region(10, 15); System.out.println("Before reset, regionStart(): " + matcher.regionStart()); System.out.println("Before reset, regionEnd(): " + matcher.regionEnd()); matcher.reset(); System.out.println("After reset, regionStart(): " + matcher.regionStart()); System.out.println("After reset, regionEnd(): " + matcher.regionEnd()); } }
让无涯教程编译并运行以上程序,这将产生以下输出-
Before reset, regionStart(): 10 Before reset, regionEnd(): 15 After reset, regionStart(): 0 After reset, regionEnd(): 18
参考链接
https://www.learnfk.com/javaregex/javaregex-matcher-reset.html
标签:reset,Java,Matcher,regionEnd,regionStart,static,matcher From: https://blog.51cto.com/u_14033984/9047932