Pattern matcher(CharSequence) method in Java with Examples Last Updated : 14 Apr, 2023 Comments Improve Suggest changes Like Article Like Report The matcher(CharSequence) method of the Pattern class used to generate a matcher that will helpful to match the given input as parameter to method against this pattern. The Pattern.matcher() method is very helpful when we need to check a pattern against a text a single time, and the default settings of the Pattern class are appropriate. Syntax: public Matcher matcher(CharSequence input) Parameters: This method accepts a single parameter input which represents the character sequence to be matched. Return Value: This method returns a new matcher for this pattern. Below programs illustrate the matcher(CharSequence) method: Program 1: Java // Java program to demonstrate // Pattern.matcher(CharSequence) method import java.util.regex.*; public class GFG { public static void main(String[] args) { // create a REGEX String String REGEX = "(.*)(ee)(.*)?"; // create the string // in which you want to search String actualString = "geeksforgeeks"; // create a Pattern Pattern pattern = Pattern.compile(REGEX); // get a matcher object Matcher matcher = pattern.matcher(actualString); // print values if match found boolean matchfound = false; while (matcher.find()) { System.out.println("found the Regex in text:" + matcher.group() + " starting index:" + matcher.start() + " and ending index:" + matcher.end()); matchfound = true; } if (!matchfound) { System.out.println("No match found for Regex."); } } } Output:found the Regex in text:geeksforgeeks starting index:0 and ending index:13 Program 2: Java // Java program to demonstrate // Pattern.matcher(CharSequence) method import java.util.regex.*; public class GFG { public static void main(String[] args) { // create a REGEX String String REGEX = "(.*)(welcome)(.*)?"; // create the string // in which you want to search String actualString = "geeksforgeeks"; // create a Pattern Pattern pattern = Pattern.compile(REGEX); // get a matcher object Matcher matcher = pattern.matcher(actualString); // print values if match found boolean matchfound = false; while (matcher.find()) { System.out.println("match found"); matchfound = true; } if (!matchfound) { System.out.println("No match found"); } } } Output:No match found References: https://docs.oracle.com/javase/10/docs/api/java/util/regex/Pattern.html#matcher(java.lang.CharSequence) Comment More infoAdvertise with us Next Article Pattern matcher(CharSequence) method in Java with Examples A AmanSingh2210 Follow Improve Article Tags : Java Java-Functions Java 8 Java-Pattern Practice Tags : Java Similar Reads Pattern matches(String ,CharSequence) method in Java with Examples The matches(String, CharSequence) method of the Pattern class in Java is used to answer whether or not the regular expression matches on the input. To do so we compile the given regular expression and attempts to match the given input against it where both regular expression and input passed as a pa 2 min read Matcher reset(CharSequence) method in Java with Examples The reset(CharSequence input) method of Matcher Class is used to reset this matcher and insert the input String passed as the parameter to this matcher. Syntax: public Matcher reset(CharSequence input) Parameters: This method takes the parameter input which is the String to be inserted into matcher 2 min read Pattern split(CharSequence) method in Java with Examples split(CharSequence) method of a Pattern class used to splits the given char sequence passed as parameter to method around matches of this pattern.This method can split charSequence into an array of String's, using the regular expression used to compile the pattern as a delimiter.so we can say that t 2 min read Pattern split(CharSequence,int) method in Java with Examples split(CharSequence, int) method of a Pattern class used to splits the given char sequence passed as parameter to method around matches of this pattern.The array returned contains each substring of the input sequence created by this method. The substrings in the array are in the order in which they o 3 min read Matcher end() method in Java with Examples The end() method of Matcher Class is used to get the offset after the last character matched of the match result already done. Syntax: public int end() Parameters: This method do not takes any parameter. Return Value: This method returns the offset after the last character matched Exception: This me 2 min read Matcher toString() method in Java with Examples The toString() method of Matcher Class is used to get the String representation of this matcher. This method is derived from the Object Class and behaves in the similar way. Syntax: public String toString() Parameters: This method takes no parameters. Return Value: This method returns a String value 2 min read Matcher start(String) method in Java with Examples The start(String string) method of Matcher Class is used to get the start index of the match result already done, from the specified string. Syntax: public int start(String string) Parameters: This method takes a parameter string which is the String from which the start index of the matched pattern 2 min read Matcher usePattern(Pattern) method in Java with Examples The usePattern() method of Matcher Class is used to get the pattern to be matched by this matcher. Syntax: public Matcher usePattern(Pattern newPattern) Parameters: This method takes a parameter newPattern which is the new pattern to be set. Return Value: This method returns a Matcher with the new P 2 min read Matcher start() method in Java with Examples The start() method of Matcher Class is used to get the start index of the match result already done. Syntax: public int start() Parameters: This method do not takes any parameter. Return Value: This method returns the index of the first character matched.0 Exception: This method throws IllegalStateE 2 min read String matches() Method in Java with Examples In Java, the matches() method in the String class checks if a string matches a specified regular expression. It is useful for validating input patterns and searching within strings. In this article, we will learn how to use the matches() method effectively in Java with examples to illustrate its fun 3 min read Like