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.
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