![]() |
VOOZH | about |
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 Matcher region(int startIndex, int endIndex)
Parameters: This method takes two parameters:
Return Value: This method returns a Matcher with the region, to be matched, constrained. Exception: This method throws IndexOutOfBoundsException if:
Below examples illustrate the Matcher.region() method: Example 1:
Before changing region, Groups found are: Geeks Geeks Geeks Geeks After changing region, Groups found are: Geeks
Example 2:
Before changing region, Groups found are: FGF FGF After changing region, Groups found are: FGF
Reference: https://docs.oracle.com/javase/9/docs/api/java/util/regex/Matcher.html#region-int-int-