Suppose I want to break this line a^b^c^d^e^^^f^g^h^^^, I just do string.split("\\^")that which returns me an array of 10 ie length [a, b, c, d, e, , , f, g, h]. However, I need an array of length 13 that accepts separator occurrences after h.
I can do something like this to achieve what I want
string = string.replace("^", "^ ");
String[] split = string.split("\\^");
for(String x : split){
System.out.println(x.trim());
}
but it seems overloaded. Is there a regex for this?
source
share