Java SE API

Matcher.lookingAt()

Test a match starting at the region beginning. Java SE API; example uses Java 21-compatible syntax.

Formal Syntax & Structure

java syntaxjava
boolean lookingAt()

Return Value

boolean

Test a match starting at the region beginning.

Working Example

Example Snippetjava
import java.util.*;import java.util.regex.*;import java.nio.*;import java.nio.charset.*;import java.io.*;import javax.xml.XMLConstants;import javax.xml.parsers.*;import org.xml.sax.*;import org.xml.sax.helpers.DefaultHandler;import org.w3c.dom.*;public class Main {    public static void main(String[] args) throws Exception {        var p = Pattern.compile("[A-Z]{2}-[0-9]{3}");        System.out.println(p.matcher("AB-123").matches());        System.out.println(p.matcher("AB-123 extra").matches());        System.out.println(p.matcher("AB-123 extra").lookingAt());        System.out.println(p.matcher("item AB-123").find());    }}
Java Reference