fork download
  1. import java.util.*;
  2. import java.util.regex.*;
  3. import java.lang.*;
  4. import java.io.*;
  5. class Ideone
  6. {
  7. public static void main (String[] args) throws java.lang.Exception
  8. {
  9. String phrase = "Heres is one line\r\n" +
  10. "and another\r" +
  11. "and another one\n" +
  12. "all with different line ending chars";
  13.  
  14. List<String> textLinesWithDelimiters = Arrays.asList(phrase.split(("")));
  15. Pattern p = Pattern.compile("\\V+|\\v+");
  16. Matcher m=p.matcher(phrase);
  17. while(m.find()) {
  18. System.out.println(m.group(0).replace("\n", "\\n").replace("\r", "\\r"));
  19. }
  20. }
  21. }
Success #stdin #stdout 0.05s 27852KB
stdin
Standard input is empty
stdout
Heres is one line
\r\n
and another
\r
and another one
\n
all with different line ending chars