/** * Splits input string by whitespaces, taking quotes into account * * @param input * @return */ private static List<String> split(String input) { final String regex = "\"([^\"]*)\"|(\\S+)"; List<String> result = new ArrayList<String>(); Matcher m = Pattern.compile(regex).matcher(input); while (m.find()) { String s = m.group(1); if (s != null) { // don't touch quoted terms result.add("\"" + s.trim() + "\""); } else { s = m.group(2); if (!isWildcardOnly(s)) result.add(s.trim()); } } return result; }