codingBat plusOut using regex

前端 未结 4 1059
离开以前
离开以前 2020-12-12 01:20

This is similar to my previous efforts (wordEnds and repeatEnd): as a mental exercise, I want to solve this toy problem using regex only.

Description from codingbat.

4条回答
  •  一整个雨季
    2020-12-12 02:03

    This passes all their tests:

    public String plusOut(String str, String word) {
      return str.replaceAll(
        String.format("(?

    Also, I get:

    plusOut("1xAxAx2", "xAx") → "+xAxAx+"
    

    If that's the result you were looking for then I pass your overlap test as well, but I have to admit, that one's by accident. :D

提交回复
热议问题