Matcher reset(CharSequence) method in Java with Examples Last Updated : 26 Nov, 2018 Comments Improve Suggest changes Like Article Like Report 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 after getting reset. Return Value: This method returns this Matcher after being reset with this input. Below examples illustrate the Matcher.reset() method: Example 1: Java // Java code to illustrate reset() method import java.util.regex.*; public class GFG { public static void main(String[] args) { // Get the regex to be checked String regex = "Geeks"; // Create a pattern from regex Pattern pattern = Pattern.compile(regex); // Get the String to be matched String stringToBeMatched = "GeeksForGeeks"; // Create a matcher for the input String Matcher matcher = pattern .matcher(stringToBeMatched); // Get the current matcher state System.out.println("Current Matcher: " + matcher.toMatchResult()); // Reset the Matcher using reset() method String newStringToBeMatched = "GeeksGeeksGeeks"; matcher = matcher .reset(newStringToBeMatched); // Get the current matcher state System.out.println("Current Matcher after Reset: " + matcher.toMatchResult()); } } Output: Current Matcher: java.util.regex.Matcher[pattern=Geeks region=0,13 lastmatch=] Current Matcher after Reset: java.util.regex.Matcher[pattern=Geeks region=0,15 lastmatch=] Example 2: Java // Java code to illustrate reset() method import java.util.regex.*; public class GFG { public static void main(String[] args) { // Get the regex to be checked String regex = "GFG"; // Create a pattern from regex Pattern pattern = Pattern.compile(regex); // Get the String to be matched String stringToBeMatched = "GFGFGFGFGFGFGFGFGFG"; // Create a matcher for the input String Matcher matcher = pattern .matcher(stringToBeMatched); // Get the current matcher state System.out.println("Current Matcher: " + matcher.toMatchResult()); // Reset the Matcher using reset() method String newStringToBeMatched = "GFG means GeeksForGeeks"; matcher = matcher .reset(newStringToBeMatched); // Get the current matcher state System.out.println("Current Matcher after Reset: " + matcher.toMatchResult()); } } Output: Current Matcher: java.util.regex.Matcher[pattern=GFG region=0,19 lastmatch=] Current Matcher after Reset: java.util.regex.Matcher[pattern=GFG region=0,23 lastmatch=] Reference: Oracle Doc Comment More infoAdvertise with us Next Article Matcher reset(CharSequence) method in Java with Examples K Kirti_Mangal Follow Improve Article Tags : Java Java - util package Java-Functions Java-Matcher Practice Tags : Java Similar Reads Pattern matcher(CharSequence) method in Java with Examples 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 2 min read Matcher reset() Method in Java with Examples The reset() method of Matcher Class is used to reset this matcher, in order to understand it better it is recommended to have prior knowledge of Pattern and Matcher class in java regex sub-package. Here we will be illustrating it with help of Java programs. Syntax: public Matcher reset() Parameters: 2 min read 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 CharsetEncoder reset() method in Java with Examples The reset() method is a built-in method of the java.nio.charset.CharsetEncoder resets this encoder, and clears all the internal states if there are any. It also resets charset-independent state and also invokes the implReset method in order to perform any charset-specific reset actions. Syntax: publ 2 min read CharsetDecoder reset() method in Java with Examples The reset() method is a built-in method of the java.nio.charset.CharsetDecoder class which resets this CharsetDecoder and clears its internal state. Syntax: public final CharsetDecoder reset() Parameters: The function does not accepts any parameter. Return Value: The function returns this CharsetDec 1 min read Like