Response without using RegEx:
import java.util.*;
class Program {
public static void main (String[] args) {
String texto = "(:TEXTOQUALQUER NADA DO FOI :TEXTOQQDENOVO SERÁ DE NOVO :TEXTOQQMAIS DO JEITO QUE UM DIA :TEXTO3343)";
List<String> textos = new ArrayList<String>();
while (texto.length() > 0) {
texto = texto.substring(texto.indexOf(":") + 1);
int posicaoParentese = texto.indexOf(")");
int posicaoEspaco = texto.indexOf(" ");
int posicaoFinal = Math.min((posicaoParentese == -1 ? Integer.MAX_VALUE : posicaoParentese), (posicaoEspaco == -1 ? Integer.MAX_VALUE : posicaoEspaco));
textos.add(texto.substring(0, posicaoFinal));
texto = texto.substring(posicaoFinal + 1);
}
for (String item : textos) System.out.println(item);
}
}
See running on ideone . And no Coding Ground . Also put it in GitHub for future reference .
I will leave the previous attempts to help anyone who has a similar problem. The question was rather confusing, forcing the answers (not just mine) to be edited to arrive at the desired result. I hope you're ok now.
Reading your question better I think you want something else, I think it would be just this.
import java.util.*;
class Program {
public static void main (String[] args) {
String texto = "(:TEXTOQUALQUER NADA DO FOI :TEXTOQQDENOVO SERÁ DE NOVO :TEXTOQQMAIS DO JEITO QUE UM DIA :TEXTO3343)";
List<String> textos = new ArrayList<String>();
while (texto.length() > 0) {
texto = texto.substring(texto.indexOf(":") + 1);
int posicaoParentese = texto.indexOf(")");
int posicaoEspaco = texto.indexOf(" ");
int posicaoFinal = Math.min((posicaoParentese == -1 ? Integer.MAX_VALUE : posicaoParentese), (posicaoEspaco == -1 ? Integer.MAX_VALUE : posicaoEspaco));
textos.add(texto.substring(0, posicaoFinal));
texto = texto.substring(posicaoFinal + 1);
}
for (String item : textos) System.out.println(item);
}
}
See running on ideone . And no Coding Ground . Also put it in GitHub for future reference .
If it has not yet been answered, you do not need RegEx for this, just a Split()
:
class Program {
public static void main (String[] args) {
String texto = "(:TEXTOQUALQUER NADA DO FOI :TEXTOQQDENOVO SERÁ DE NOVO :TEXTOQQMAIS DO JEITO QUE UM DIA :TEXTO3343)";
String[] textos = texto.split(":");
for (String item : textos) System.out.println(item);
}
}
See running on ideone . And no Coding Ground . Also I've placed GitHub for future reference .
If you do not want what comes before the first :
simply ignore element 0 of arryay (texts [0]).