List<String> parse(String s) {
        List<String> words = new ArrayList<>();
        String field = "";

        Matcher matcher = SHELLWORDS.matcher(s);
        while (matcher.find()) {
            String word = matcher.group(1);
            String sq = matcher.group(2);
            String dq = matcher.group(3);
            String esc = matcher.group(4);
            String garbage = matcher.group(5);
            String sep = matcher.group(6);

            if (garbage != null) {
                throw new IllegalArgumentException("Unmatched double quote: " + s);
            }

            if (word != null) {
                field = word;
            } else if (sq != null) {
                field = sq;
            } else if (dq != null) {
                field = dq.replaceAll("\\\\(?=.)", "");
            } else if (esc != null) {
                field = esc.replaceAll("\\\\(?=.)", "");
            }

            if (sep != null) {
                words.add(field);
                field = "";
            }
        }

        return words;
    }
Parses a string into a collection of words based on POSIX standard

@param s the string to parse
@return the collection of words
extensions/spring-xd-extension-process/src/main/java/org/springframework/xd/extension/process/ShellWordsParser.java