I have a source line that I want to break dataout:
String source = "data|junk,data|junk|junk,data,data|junk";
String[] result = source.split(",");
The above gives data|junk, data|junk|junk, data, data|junk. To get the data, I did the following:
for (int i = 0; i < result.length; i++) {
result[i] = result[i].split("\\|")[0];
}
Which gives what I wanted data, data, data, data. I want to see if this can be done in the same split with the correct regular expression:
String[] result = source.split("\\|.*?,");
The above gives data, data, data,data|junkin which the last two data are not split. Could you help with the correct regular expression to get the result I wanted?
Example line: "Ann | xcjiajeaw, Bob | aijife | vdsjisdjfe, Clara, David | rijfidjf"
Expected Result: "Anne, Bob, Clara, David"