fork(1) download
  1. import java.util.regex.Matcher;
  2. import java.util.regex.Pattern;
  3.  
  4. public class Main {
  5.  
  6. public static void main (String[] args) {
  7.  
  8. String input = "foobar foo bar 'foobar' 'foo bar' 'foo''bar'";
  9. Pattern pattern = Pattern.compile("'(?:[^']|'')+'|[^ ]+");
  10. Matcher matcher = pattern.matcher(input);
  11. while (matcher.find()) {
  12. String match = matcher.group();
  13. System.out.println(match);
  14. }
  15.  
  16. }
  17.  
  18. }
Success #stdin #stdout 0.07s 381248KB
stdin
Standard input is empty
stdout
foobar
foo
bar
'foobar'
'foo bar'
'foo''bar'