Matcher regionStart() method in Java with Examples Last Updated : 27 Nov, 2018 Comments Improve Suggest changes Like Article Like Report The regionStart() method of Matcher Class is used to get the startIndex of the region to be matched by the pattern in the current matcher. This method returns an integer value which is the startIndex of the region of this matcher. Syntax: public int regionStart() Parameters: This method takes no parameters. Return Value: This method returns a integer value which is the startIndex of the region of this matcher. Below examples illustrate the Matcher.regionStart() method: Example 1: Java // Java code to illustrate regionStart() 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 Geeks for For Geeks Geek"; // Create a matcher for the input String Matcher matcher = pattern.matcher(stringToBeMatched); // Get previous startIndex of region // using regionStart() method System.out.println("Before changing region, " + " Region starts from: " + matcher.regionStart()); // Restrict the region to 2, 10 matcher = matcher.region(2, 10); // Get previous startIndex of region // using regionStart() method System.out.println("After changing region, " + " Region starts from: " + matcher.regionStart()); } } Output: Before changing region, Region starts from: 0 After changing region, Region starts from: 2 Example 2: Java // Java code to illustrate regionStart() method import java.util.regex.*; public class GFG { public static void main(String[] args) { // Get the regex to be checked String regex = "(F*F)"; // Create a pattern from regex Pattern pattern = Pattern.compile(regex); // Get the String to be matched String stringToBeMatched = "GFGFGFGFGFGFGFGFGFG FGF GFG GFG FGF"; // Create a matcher for the input String Matcher matcher = pattern.matcher(stringToBeMatched); // Get previous startIndex of region // using regionStart() method System.out.println("Before changing region, " + " Region starts from: " + matcher.regionStart()); // Restrict the region to 5, 10 matcher = matcher.region(5, 10); // Get previous startIndex of region // using regionStart() method System.out.println("After changing region, " + " Region starts from: " + matcher.regionStart()); } } Output: Before changing region, Region starts from: 0 After changing region, Region starts from: 5 Reference: https://docs.oracle.com/javase/9/docs/api/java/util/regex/Matcher.html#regionStart-- Comment More infoAdvertise with us Next Article Matcher regionStart() 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 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 Matcher regionEnd() method in Java with Examples The regionEnd() method of Matcher Class is used to get the endIndex of the region to be matched by the pattern in the current matcher. This method returns an integer value which is the endIndex of the region of this matcher. Syntax: public int regionEnd() Parameters: This method takes no parameters. 2 min read Matcher start(int) method in Java with Examples The start(int group) method of Matcher Class is used to get the start index of the match result already done, from the specified group. Syntax: public int start(int group) Parameters: This method takes a parameter group which is the group from which the start index of the matched pattern is required 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 region(int, int) method in Java with Examples The region(int, int) method of Matcher Class restricts the region to be matched by the pattern. This region must be lesser than or same as the previous region, but not greater. Else it would lead to IndexOutOfBoundsException. This method returns a Matcher with the new matching region. Syntax: public 3 min read Like