fork(5) 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+\\S+)(?=\\s|$))")
  7. .matcher("word1 word2 word3 word4");
  8. while (m.find()) {
  9. System.out.println(m.group(1));
  10. }
  11. }
  12. }
Success #stdin #stdout 0.02s 245632KB
stdin
Standard input is empty
stdout
word1 word2
word2 word3
word3 word4