Java: Find index of first Regex

前端 未结 4 1923
暗喜
暗喜 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 04:52

    As requested a more complete solution:

        /** @return index of pattern in s or -1, if not found */
    public static int indexOf(Pattern pattern, String s) {
        Matcher matcher = pattern.matcher(s);
        return matcher.find() ? matcher.start() : -1;
    }
    

    call:

    int index = indexOf(Pattern.compile("(?

提交回复
热议问题