是否是最后一人匹配项,如果是则返回true。
boolean hitEnd() - 声明
以下是 java.time.Matcher.hitEnd()方法的声明。
public boolean hitEnd()
boolean hitEnd() - 返回值
如果是最后一个匹配项,则返回为true;否则为false
boolean hitEnd() - 示例
下面的示例显示java.time.Matcher.hitEnd()方法的用法。
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); //get a matcher object Matcher matcher = pattern.matcher(INPUT); while(matcher.find()) { //Prints the offset after the last character matched. System.out.println("First Capturing Group, (a*b) Match String end(): "+matcher.end()); } System.out.println("hitEnd(): "+matcher.hitEnd()); } }
让无涯教程编译并运行以上程序,这将产生以下输出-
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 hitEnd(): true
参考链接
https://www.learnfk.com/javaregex/javaregex-matcher-hitend.html
标签:Java,String,Matcher,无涯,boolean,matcher,hitEnd,end From: https://blog.51cto.com/u_14033984/9042192