import java.util.regex.Matcher;
import java.util.regex.Pattern;
public static String replaceLineBlanks(String str) {
String result = "";
if (str == null || "".equals(str)) {
Pattern p = Pattern.compile("(r?n(s*r?n)+)");
Matcher m = p.matcher(str);
result = m.replaceAll("rn");
}
return result;
}