Matcher lookingAt() method in Java with Examples
The lookingAt() method of Matcher Class attempts to match the pattern partially or fully in the matcher. It returns a boolean value showing if the pattern was matched even partially or fully starting from the start of the pattern.
Syntax:
public boolean lookingAt()
Parameters: This method do not takes any parameter.
Return Value: This method returns a boolean value showing if a prefix of the input sequence matches this matcher’s pattern.
Below examples illustrate the Matcher.lookingAt() method:
Example 1:
import java.util.regex.*;
public class GFG {
public static void main(String[] args)
{
String regex = "Geeks" ;
Pattern pattern
= Pattern.compile(regex);
String stringToBeMatched
= "GeeksForGeeks" ;
Matcher matcher
= pattern
.matcher(stringToBeMatched);
System.out.println(matcher.lookingAt());
}
}
|
Example 2:
import java.util.regex.*;
public class GFG {
public static void main(String[] args)
{
String regex = "GFG" ;
Pattern pattern
= Pattern.compile(regex);
String stringToBeMatched
= "GFGFGFGFGFGFGFGFGFG" ;
Matcher matcher
= pattern
.matcher(stringToBeMatched);
System.out.println(matcher.lookingAt());
}
}
|
Reference: https://docs.oracle.com/javase/9/docs/api/java/util/regex/Matcher.html#lookingAt–
Last Updated :
26 Nov, 2018
Like Article
Save Article
Share your thoughts in the comments
Please Login to comment...