fork download
  1. import java.util.*;
  2. import java.lang.*;
  3. import java.io.*;
  4. import java.util.regex.Matcher;
  5. import java.util.regex.Pattern;
  6.  
  7. class Ideone
  8. {
  9. public static void main (String[] args) throws java.lang.Exception
  10. {
  11. String pattern = "((?:\\S*\\s*){2}$)|.";
  12. String input = "The man is very tall.";
  13.  
  14. System.out.println(input.replaceAll(pattern, "$1"));
  15. }
  16. }
Success #stdin #stdout 0.1s 320576KB
stdin
Standard input is empty
stdout
very   tall.