Here you can find the source of extractLanguageRelativePath(final Path absolutePath)
private static String extractLanguageRelativePath(final Path absolutePath)
//package com.java2s; //License from project: Apache License import java.io.File; import java.nio.file.Path; import java.util.regex.Matcher; import java.util.regex.Pattern; public class Main { private static final String CONFIG_NAMES_FILE_TOC = "toc.html"; private static String extractLanguageRelativePath(final Path absolutePath) { final String fileName; if (absolutePath != null && absolutePath.getFileName() != null) { fileName = absolutePath.getFileName().toString(); } else {/* www .j av a 2s .c o m*/ fileName = ""; } final String pathRegexSeparator; if ("\\".equals(File.separator)) { pathRegexSeparator = "\\\\"; } else { pathRegexSeparator = File.separator; } final String languagePathPattern = "(it|en|fr)" + pathRegexSeparator + "(faq|imgs|pages|pdf|toc\\.html)"; Pattern pattern = Pattern.compile(languagePathPattern); final String pathString; if (absolutePath != null) { pathString = absolutePath.toString(); } else { pathString = ""; } Matcher matcher = pattern.matcher(pathString); String lang = ""; String folderType = ""; while (matcher.find()) { lang = matcher.group(1); folderType = matcher.group(2); } String result = lang + File.separator + folderType; if (result.endsWith(File.separator)) { result = fileName; } else if (!fileName.equals(CONFIG_NAMES_FILE_TOC)) { result += File.separator + fileName; } return result; } }