java.util.regex.Matcher.reset(CharSequence input)方法使用新的输入序列重置此匹配器。
Matcher reset - 声明
public Matcher reset(CharSequence input)
input - 新的输入字符序列。
Matcher reset - 返回值
这个匹配器。
Matcher reset - 示例
下面的示例显示java.util.regex.Matcher.reset(CharSequence input)方法的用法。
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 INPUT1 = "fooabfoob"; private static String REPLACE = "-"; public static void main(String[] args) { Pattern pattern = Pattern.compile(REGEX); //获取匹配器对象 Matcher matcher = pattern.matcher(INPUT); while(matcher.find()) { //在匹配的最后一个字符之后打印偏移量。 System.out.println("First Capturing Group, (a*b) Match String end(): "+matcher.end()); } matcher.reset(INPUT1); System.out.println("RESET"); while(matcher.find()) { //在匹配的最后一个字符之后打印偏移量。 System.out.println("First Capturing Group, (a*b) Match String end(): "+matcher.end()); } } }
让无涯教程编译并运行以上程序,这将产生以下输出-
First Capturing Group, (a*b) Match String end(): 6 First Capturing Group, (a*b) Match String end(): 12 First Capturing Group, (a*b) Match String end(): 17 RESET First Capturing Group, (a*b) Match String end(): 8
参考链接
https://www.learnfk.com/javaregex/javaregex-matcher-reset1.html
标签:reset,end,String,Group,Matcher,matcher,Java From: https://blog.51cto.com/u_14033984/9048466