📜  java 在两个或多个空格上拆分字符串,引号中的单词除外 - Java 代码示例

📅  最后修改于: 2022-03-11 14:52:31.943000             🧑  作者: Mango

代码示例1
String str = "Location \"Welcome  to india\" Bangalore " +
             "Channai \"IT city\"  Mysore";

List list = new ArrayList();
Matcher m = Pattern.compile("([^\"]\\S*|\".+?\")\\s*").matcher(str);
while (m.find())
    list.add(m.group(1)); // Add .replace("\"", "") to remove surrounding quotes.


System.out.println(list);