fork download
  1. import java.util.*;
  2. import java.util.regex.*;
  3.  
  4. class Ideone
  5. {
  6. public static void main (String[] args) throws java.lang.Exception
  7. {
  8. String s = "abc def a(xy) / pq";
  9. Pattern pattern = Pattern.compile("^\\w+(?:\\s+\\w+)*");
  10. Matcher matcher = pattern.matcher(s);
  11. while (matcher.find()){
  12. System.out.println(matcher.group(0));
  13. }
  14. }
  15. }
Success #stdin #stdout 0.09s 50032KB
stdin
Standard input is empty
stdout
abc def a