Java: Find index of first Regex

前端 未结 4 1922
暗喜
暗喜 2020-12-18 04:07

I need to change a piece of code which includes this:

string.indexOf(\"bc\")

How can this be changed by a solution that skips the occurrenc

4条回答
  •  佛祖请我去吃肉
    2020-12-18 05:09

    To add to Arne's answer - if you wanted to also add indexing:

    public static int indexOf(String regex, String s, int index)
    {
        Pattern pattern = Pattern.compile(regex);
        Matcher matcher = pattern.matcher(s);
        return matcher.find(index) ? matcher.start() : -1;
    }
    

    call:

    int index = indexOf("(?

提交回复
热议问题