fork(2) download
  1. import java.util.regex.Matcher;
  2. import java.util.regex.Pattern;
  3.  
  4. public class Main {
  5. public static void main(String[] argv) throws Exception {
  6. Matcher m = Pattern.compile("(?:^|(?<=\\s))(?=((?:\\S+\\s+){2}\\S+)(?=\\s|$))")
  7. .matcher("word1 word2 word3 word4 word6 word6");
  8. while (m.find()) {
  9. System.out.println(m.group(1));
  10. }
  11. }
  12. }
Success #stdin #stdout 0.04s 4386816KB
stdin
word1 word2 word3 word4 word5 word6 word7
stdout
word1 word2 word3
word2 word3 word4
word3 word4 word6
word4 word6 word6