java.util.regex.Matcher.regionStart() 匹配器区域的起始索引。
int regionStart() - 声明
public int regionStart()
int regionStart() - 示例
下面的示例显示java.util.regex.Matcher.regionStart()方法的用法。
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 = matcher.region(0, 10); while(matcher.find()) { //在匹配的最后一个字符之后打印偏移量。 System.out.println("First Capturing Group, (a*b) Match String end(): "+matcher.end()); } System.out.println("regionStart(): "+matcher.regionStart()); } }
让无涯教程编译并运行以上程序,这将产生以下输出-
First Capturing Group, (a*b) Match String end(): 6 regionStart(): 0
参考链接
https://www.learnfk.com/javaregex/javaregex-matcher-regionstart.html
标签:Java,String,int,Matcher,regionStart,static,matcher From: https://blog.51cto.com/u_14033984/9047620