Java Matcher group() MethodThe group method returns the matched input sequence captured by the previous match in the form of the string. This method returns the empty string when the pattern successfully matches the empty string in the input. SignatureThere are 3 types of group method in java. The signature of group methods are given below
Specified byThe group in interface MatchResult ReturnsThe (possibly empty) subsequence matched by the previous match, in string form ThrowsIllegalStateException - If no match has yet been attempted, or if the previous match operation failed. Example 1Test it NowOutput: Start :1, End : 4, Group abb Start :4, End : 7, Group abb Start :7, End : 10,Group abb Example 2Test it NowOutput: Group 0 is Group 1 s My name is Khan and m not a terrerist. Example 3Test it NowOutput: Hello world Note: Here the group name java contains all the alphabets both small and capital.
Next TopicJava Matcher class
|