Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/regex/19.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
使用Java解析多个双引号文件名_Java_Regex_String - Fatal编程技术网

使用Java解析多个双引号文件名

使用Java解析多个双引号文件名,java,regex,string,Java,Regex,String,我只想用双引号括起包含多个文件名的行(这是Windows在文件对话框中选择多个文件时使用的方法),并将它们作为单独的字符串返回 i、 e给定 "C:\MusicMatched2\Gold Greatest Hits" "C:\MusicMatched2\The Trials of Van Occupanther" 我想将其解码为两个字符串: C:\MusicMatched2\Gold Greatest Hits C:\MusicMatched2\The Trials of Van Occupa

我只想用双引号括起包含多个文件名的行(这是Windows在文件对话框中选择多个文件时使用的方法),并将它们作为单独的字符串返回

i、 e给定

"C:\MusicMatched2\Gold Greatest Hits" "C:\MusicMatched2\The Trials of Van Occupanther"
我想将其解码为两个字符串:

C:\MusicMatched2\Gold Greatest Hits
C:\MusicMatched2\The Trials of Van Occupanther
我通常使用String.split(),但在这种情况下这不好,有人能帮忙吗

答案,答案中给出的regexp按如下方式执行:

        Pattern p = Pattern.compile("\"([^\"]++)\"");
        Matcher matcher =p.matcher("C:\MusicMatched2\Gold Greatest Hits" "C:\MusicMatched2\The Trials of Van Occupanther");
        while(matcher.find()) {
            System.out.println(matcher.group(1));
        }

最快的模式可能是:

"\"([^\"]++)\""
使用find方法,结果是捕获组1。

是否使用拆分工作的
“\”(\\s+\”)?
获取多个“arg”?
    String s = "\"C:\\MusicMatched2\\Gold Greatest Hits\" \"C:\\MusicMatched2\\The Trials of Van Occupanther\"";
    Pattern p = Pattern.compile("\"(.*?)\"");
    Matcher matcher = p.matcher(s);
    while (matcher.find()) {
        System.out.println(matcher.group(1));
    }