Javatpoint Logo
Javatpoint Logo

Java Matcher start() Method

This method is used to return the start index of the previous match. To return the offset of first matched character, we need to use the find method to match the pattern character by character.

Signature

There are 3 types of start method in java. The signature of the start methods is given below.

No. Method Method Name
1 int start() This method returns the offset after the matching of the first character.
2 int start(int group) This method returns the offset by matching the starting character of the subsequence captured by the given group.
3 int start(String name) This method returns the offset after matching of the starting character of the subsequence captured by the given name of the group.

Specified by:

start in interface MatchResult

Returns:

The index of the first character matched

Throws:

IllegalStateException- If no match has yet been attempted, or if the previous match operation failed

Example 1

Test it Now

Output:

Start position :1, End position : 4
Start position :4, End position : 7
Start position :7, End position : 10

Example 2

Test it Now

Output:

start position of Matching String java 2

Example 3

Test it Now

Output:

Start position of matching 5

Next TopicJava Matcher class




Help Others, Please Share

facebook twitter pinterest