I thought that wasn\'t that hard to do, but I want to remove all empty lines (or lines just containing blanks and tabs in Java) with String.replaceAll.
My regex look
Try this:
String text = "line 1\n\nline 3\n\n\nline 5"; String adjusted = text.replaceAll("(?m)^[ \t]*\r?\n", ""); // ...
Note that the regex [ |\t] matches a space, a tab or a pipe char!
[ |\t]
B.t.w., the regex (?m)^\s+$ would also do the trick.
(?m)^\s+$