Since the question is for Java and based on @SubOptimal answer , which explains that paths with a semicolon should be enclosed in quotation marks, here is a small example of code for extracting paths from such a list, separated by the File.pathSeparator symbol:
String separatedList = "\"test;test1\";c:\\windows;\"test2\";test3;;test4"; String pattern = String.format("(?:(?:\"([^\"]*)\")|([^%1$s]+))%1$s?", File.pathSeparator); Pattern p = Pattern.compile(pattern); Matcher m = p.matcher(separatedList); while (m.find()) { for (int i = 1; i <= m.groupCount(); i++) { String path = m.group(i); if (path != null) System.out.println(path); } }
For reference, a regular expression without escape characters (?:(?:"([^"]*)")|([^;]+));? .
source share