使用Java解析多个双引号文件名
我只想用双引号括起包含多个文件名的行(这是Windows在文件对话框中选择多个文件时使用的方法),并将它们作为单独的字符串返回 i、 e给定使用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
"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));
}