fork download
  1. import java.util.*;
  2. import java.lang.*;
  3. import java.io.*;
  4. import java.util.regex.*;
  5. class Ideone
  6. {
  7. public static void main (String[] args) throws java.lang.Exception
  8. {
  9. String s_lf = "this tis a fine #line1\nthis tis another fine #line2\nthis_belongs_to abobe line\nthis tis still is OK #line4";
  10. String s_crlf = "this tis a fine #line1\r\nthis tis another fine #line2\r\nthis_belongs_to abobe line\r\nthis tis still is OK #line4";
  11.  
  12. System.out.println(s_lf.replaceAll("\\R(?!.*#)", ""));
  13. System.out.println(s_crlf.replaceAll("\\R(?!.*#)", ""));
  14.  
  15. System.out.println(s_lf.replaceAll("(?m)\\R(?=[^\n#]+$)", ""));
  16. System.out.println(s_crlf.replaceAll("(?m)\\R(?=[^\n#]+$)", ""));
  17. }
  18. }
Success #stdin #stdout 0.09s 48468KB
stdin
Standard input is empty
stdout
this tis a fine #line1
this tis another fine #line2this_belongs_to abobe line
this tis still is OK #line4
this tis a fine #line1
this tis another fine #line2this_belongs_to abobe line
this tis still is OK #line4
this tis a fine #line1
this tis another fine #line2this_belongs_to abobe line
this tis still is OK #line4
this tis a fine #line1
this tis another fine #line2this_belongs_to abobe line
this tis still is OK #line4