Method Boolean lookingAt()

The lookingAt()method attempts to match the input against the pattern, starting from the beginning of the input but without requiring that the entire region be matched against the pattern. The following code demonstrates it:

package example.regex; import java.util.regex.*; class MatcherLookingatExample {   public static void main (String[] args)   {     final Pattern pattern1 = Pattern.compile("master[a-z]*");     final Pattern pattern2 = Pattern.compile("master");     final Pattern pattern3 = Pattern.compile("regular");     String input = "mastering regular expressions";     Matcher matcher = pattern1.matcher(input);     System.out.printf("[%s] => [%s]: %s%n", input, matcher.pattern(),     matcher.lookingAt());  // update the matcher's ...

Get Java 9 Regular Expressions now with the O’Reilly learning platform.

O’Reilly members experience live online training, plus books, videos, and digital content from nearly 200 publishers.