Pattern p = Pattern.compile("\\s{2,}|\t"); Matcher m = p.matcher(str); String strNoBlank = m.replaceAll(" "); System.out.println(strNoBlank);