0

你知道这里有什么问题吗?

    Pattern pathsPatter = Pattern.compile("\"([^\"]+)\"");
    Matcher pathsMatcher = pathsPatter.matcher(commandAndParameters[1]);

我想捕获“”之间的组。例如,如果字符串是

    mv "C:\Users\" "D:\"

匹配器应捕获:

    C:\Users\
    D:\
4

2 回答 2

1

试试这个模式:

    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));
    }
于 2013-03-17T11:31:38.713 回答
0

在这里工作正常:

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:\
于 2013-03-17T11:21:16.847 回答