Daredevi1 Daredevi1 - 2 months ago 9
Java Question

Java regex to remove everything between character 'i' and ':'

I have the following String


and I need to do the following:

  1. Remove everything between
    and replace it with

  2. Remove

  3. Remove

I want to end up with

I've had an attempt at it but it doesn't quite do what I want. The following is what I've written:

numbers = numbers.replaceAll("\\D.*?:", ",");

I get the following result:

Notice how it has removed the first set of numbers (9201).

Can anyone suggest the regex I should be using please?


Here you go:

String str = "{TEXT=9201i3:9830i22:90400i11:92710i7:94500|HELLO_UK}"
        .replaceAll("(\\{TEXT=|\\|HELLO_UK\\})", "")
        .replaceAll("i(.*?):", ",");