Regular Expression find method

前端 未结 2 1965
没有蜡笔的小新
没有蜡笔的小新 2021-01-14 22:25

This is my code to find \"ab\" pattern in given string.

import java.util.regex.*;
public class RegExp
{
    public static void main(String[] arg         


        
2条回答
  •  一个人的身影
    2021-01-14 23:26

    The find method scans the input sequence looking for the next subsequence that matches the pattern and returns a boolean indicating the success of failure.

    Internally find method calls the search method (access control default) so that initiates a search to find a Pattern within the given bounds. At each match the bound will be incremented until all the matches were found.

    Behind the Matcher class it's a state machine that will hold the state of the match.

    On the other hand start method returns the start index as int of the subsequence captured by the latest match.

    If you want really go deeper I suggest to review the source code of Matcher class.

提交回复
热议问题