fork(1) download
  1. /* package whatever; // don't place package name! */
  2.  
  3. import java.util.*;
  4. import java.util.regex.*;
  5. import java.util.stream.Collectors;
  6.  
  7. class Ideone {
  8. public static void main (String[] args) throws java.lang.Exception {
  9. String myString = "IF What young > old, 'Price 1', 'Prediction One', 'Mother''s Day', good";
  10.  
  11. List<String> list = Pattern.compile("'[^']*'|(\\w+)")
  12. .matcher(myString)
  13. .results()
  14. .filter(res -> res.group(1) != null)
  15. .map(res -> res.group(1))
  16. .collect(Collectors.toList());
  17.  
  18. System.out.printf("List: %s%n", list);
  19. }
  20. }
Success #stdin #stdout 0.12s 56508KB
stdin
Standard input is empty
stdout
List: [IF, What, young, old, good]