I'm using java to split a String of the form:
String stringToSplit = "AAA BBB CCC DDD EEE FFF GGG HHH III JJJ KKK";
I'm using
String[] tokens = stringToParse.split("\\s");
to split the strings along whitespace, giving:
tokens = {"AAA","BBB","CCC", "DDD","EEE","FFF","GGG","HHH","III", "JJJ", "KKK"}
What I need to do now is split along whitespace for most of them, but also keep some strings together in specific cases. For instance, I want "CCC DDD" and "III JJJ KKK" to stay as their full strings when I split. So I want my array of tokens to be:
tokens = {"AAA","BBB","CCC DDD","EEE","FFF","GGG","HHH","III JJJ KKK"}
What regex would I use? Is this possible?
substring()instead of regex.