扫码一下
查看教程更方便
Regex类 lookingAt() 方法 尝试将从区域开头开始的输入序列与该模式匹配。
public boolean lookingAt()
无
当且仅当输入序列的前缀与此匹配器的模式匹配时才返回true。
import java.util.regex.Matcher; import java.util.regex.Pattern; public class MatcherDemo { private static final String REGEX = "foo"; private static final String INPUT = "fooooooooooooooooo"; private static Pattern pattern; private static Matcher matcher; public static void main( String args[] ) { pattern = Pattern.compile(REGEX); matcher = pattern.matcher(INPUT); System.out.println("Current REGEX is: "+REGEX); System.out.println("Current INPUT is: "+INPUT); System.out.println("lookingAt(): "+matcher.lookingAt()); System.out.println("matches(): "+matcher.matches()); } }
上面示例编译运行结果如下
Second Capturing Group, (foo) Match String end(): 3
Second Capturing Group, (foo) Match String end(): 9
Second Capturing Group, (foo) Match String end(): 14