I have a String called raw. I am trying to split it into an array like so:
lines = raw.split("\\r?\\n|\\r");
This works well for the first few occurrences but then it breaks and totally loses the rest of the string. E.g. raw is This is my string\n\nThis is a new paragraph\nThis is another line and becomes {"This is my string", "", "This is a new paragraph"}. Is this a bug within Java or am I doing something wrong? How can I fix it?
Edit: I do want to keep blank lines. [\\n\\r]+ does not keep blank lines
split, I get 4 items, as expected:{"This is my string", "", "This is a new paragraph", "This is another line"}.