I would like to replace some texts in StringBuilder. How to do this?
In this code I got java.lang.StringIndexOutOfBoundsException
at line with mat
Maybe:
int lookIndex = 0;
while (lookIndex < builder.length() && matcher.find(lookIndex)) {
lookIndex = matcher.start()+1;
builder.replace(matcher.start(), matcher.end(), repl);
}
...?
.find(n) with an integer argument claims to reset the matcher before it starts looking at the specified index. That would work around the issues raised in maartinus comment above.