// Collection of code snippets by Arne Vajhøj 
// (likely posted to comp.os.vms/INFO-VAX, INFO-TPU, MACRO32, eksperten.dk, newz.dk, LinkedIn or other place sometime between 1990 and now) 
public class RegexSub {
    public static void main(String[] args) throws Exception {
        String foo = "1\r\n2\r3\r\n";
        System.out.println(foo);
        System.out.println(foo.length());
        System.out.println(foo.replaceAll("\r(?=[^\n])", "\r\n"));
        System.out.println(foo.replaceAll("\r(?=[^\n])", "\r\n").length());
    }
}
