remove Carriage Return with regex - Java java.util.regex

Java examples for java.util.regex:Match New Line

Description

remove Carriage Return with regex

Demo Code

//package com.java2s;

public class Main {
    public static void main(String[] argv) {
        String query = "boo\r\n\n\n\nk2s.com";
        System.out.println(removeCarriageReturn(query));
    }//from w w  w .  j ava2  s  .  c  om

    public static String removeCarriageReturn(String query) {
        //        query.replaceAll(regex, replacement)
        String result = query.replaceAll("[\r\n]", " ");
        return result;
    }
}

Related Tutorials