Java Matcher lookingAt() method

The lookingAt() method of Matcher class is used to match the input sequence against the beginning of the text. This method is similar to matches() except the difference that matches() match the regular expression against the whole text.

Syntax:

Parameter

No parameter

Returns

true if, and only if, a prefix of the input sequence matches this matcher's pattern

Example 1

Output:

lookingAt = true

Example 2

Output:

lookingAt = true
matches   = false

Example 3

Output:

  lookingAt = true
  java.util.regex.Matcher[pattern=java programm region=0,50 lastmatch=java programm]