fork(2) download
  1. import java.util.*;
  2.  
  3. class Ideone
  4. {
  5. public static void main (String[] args) throws java.lang.Exception
  6. {
  7. String text = "\u00A0 \u00A0\tStart reading\u00A0here...";
  8. System.out.println("Text: '" + text + "'");
  9. System.out.println(text.replaceAll("(?U)\\s+", "")); // removes all whitespaces
  10. System.out.println(text.replaceAll("(?U)\\s", "-")); // replaces each single whitespace with -
  11. System.out.println(text.replaceAll("(?U)\\s+", "-")); // replaces chunks of one or more consecutive whitespaces with a single -
  12. System.out.println(text.replaceAll("(?U)\\G\\s", "-")); // replaces each single whitespace at the start of string with -
  13. }
  14. }
Success #stdin #stdout 0.14s 50452KB
stdin
Standard input is empty
stdout
Text: '   	Start reading here...'
Startreadinghere...
----Start-reading-here...
-Start-reading-here...
----Start reading here...