你知道这里有什么问题吗?
Pattern pathsPatter = Pattern.compile("\"([^\"]+)\"");
Matcher pathsMatcher = pathsPatter.matcher(commandAndParameters[1]);
我想捕获“”之间的组。例如,如果字符串是
mv "C:\Users\" "D:\"
匹配器应捕获:
C:\Users\
D:\
试试这个模式:
String data = "mv \"C:\\Users\\\" \"D:\\\"";
Pattern pattern = Pattern.compile("\"(.+?)\"");
Matcher matcher = pattern.matcher(data);
System.out.println("Started");
while (matcher.find()) {
System.out.println(matcher.group(1));
}
在这里工作正常:
Pattern pathsPattern = Pattern.compile("\"([^\"]+)\"");
Matcher pathsMatcher = pathsPattern.matcher("mv \"C:\\Users\\\" \"D:\\\"");
pathsMatcher.find();
System.out.println("found " + pathsMatcher.group(1)); // prints: found C:\Users\
pathsMatcher.find();
System.out.println("found " + pathsMatcher.group(1)); // prints: found D:\