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: This method does not take any parameters.
Return Value: This method returns this Matcher after being reset.
Example 1:
Java
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);
matcher = matcher.reset();
System.out.println(matcher.toMatchResult());
}
}
|
Output
java.util.regex.Matcher$ImmutableMatchResult@448139f0
Example 2:
Java
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);
matcher = matcher.reset();
System.out.println(matcher.toMatchResult());
}
}
|
Output
java.util.regex.Matcher$ImmutableMatchResult@448139f0
Last Updated :
25 Apr, 2023
Like Article
Save Article
Share your thoughts in the comments
Please Login to comment...