Returns a regular expression for a filepath that can include standard
file system wildcard characters (e.g. * and ?)

@param filespec A filespec that can contain wildcards
@return A regular expression to match paths specified by <code>filespec</code>
513506
protected Pattern toRegexp(String filespec) {
		Matcher m = escaper.matcher(filespec);
		StringBuffer sb = new StringBuffer();
		while (m.find()) {
			String matched = m.group(0);
			if (matched.equals("*")) {  //$NON-NLS-1$
				m.appendReplacement(sb, "\\[^/]*?"); //$NON-NLS-1$
			} else if (matched.equals("?")) {  //$NON-NLS-1$
				m.appendReplacement(sb, "[^/]"); //$NON-NLS-1$
			} else if (matched.equals("$")) { //$NON-NLS-1$
				m.appendReplacement(sb, "\\\\\\$"); //$NON-NLS-1$
			} else if (matched.equals("\\")) { //$NON-NLS-1$
				m.appendReplacement(sb, "\\\\\\\\"); //$NON-NLS-1$
			} else {
				m.appendReplacement(sb, "\\\\" + matched); //$NON-NLS-1$
			}
		}
		m.appendTail(sb);
		String patStr = sb.toString();
		return Pattern.compile((patStr.startsWith("/") ? BLANK : "(^|/)") + //$NON-NLS-1$ //$NON-NLS-2$
				patStr + "$", Pattern.CASE_INSENSITIVE); //$NON-NLS-1$
	}
490749
def _parse_file_spec(self, spec):
        '''
        
        '''
        # separate wildcard specs into more specs
        if '*' in spec['file']:
            expanded_paths = _expand_paths(spec['file'])
            if not expanded_paths:
                return []
            expanded_specs = []
            for p in expanded_paths:
                _spec = copy.copy(spec)
                _spec['file'] = p
                expanded_specs.append(_spec)
            return expanded_specs

        else:
            return [spec]
31447
static boolean matchPath(String[] tokenizedPattern, String[] strDirs, boolean isCaseSensitive) {
        int patIdxStart = 0;
        int patIdxEnd = tokenizedPattern.length - 1;
        int strIdxStart = 0;
        int strIdxEnd = strDirs.length - 1;

        // up to first '**'
        while (patIdxStart <= patIdxEnd && strIdxStart <= strIdxEnd) {
            String patDir = tokenizedPattern[patIdxStart];
            if (patDir.equals(DEEP_TREE_MATCH)) {
                break;
            }
            if (!match(patDir, strDirs[strIdxStart], isCaseSensitive)) {
                return false;
            }
            patIdxStart++;
            strIdxStart++;
        }
        if (strIdxStart > strIdxEnd) {
            // String is exhausted
            for (int i = patIdxStart; i <= patIdxEnd; i++) {
                if (!tokenizedPattern[i].equals(DEEP_TREE_MATCH)) {
                    return false;
                }
            }
            return true;
        } else {
            if (patIdxStart > patIdxEnd) {
                // String not exhausted, but pattern is. Failure.
                return false;
            }
        }

        // up to last '**'
        while (patIdxStart <= patIdxEnd && strIdxStart <= strIdxEnd) {
            String patDir = tokenizedPattern[patIdxEnd];
            if (patDir.equals(DEEP_TREE_MATCH)) {
                break;
            }
            if (!match(patDir, strDirs[strIdxEnd], isCaseSensitive)) {
                return false;
            }
            patIdxEnd--;
            strIdxEnd--;
        }
        if (strIdxStart > strIdxEnd) {
            // String is exhausted
            for (int i = patIdxStart; i <= patIdxEnd; i++) {
                if (!tokenizedPattern[i].equals(DEEP_TREE_MATCH)) {
                    return false;
                }
            }
            return true;
        }

        while (patIdxStart != patIdxEnd && strIdxStart <= strIdxEnd) {
            int patIdxTmp = -1;
            for (int i = patIdxStart + 1; i <= patIdxEnd; i++) {
                if (tokenizedPattern[i].equals(DEEP_TREE_MATCH)) {
                    patIdxTmp = i;
                    break;
                }
            }
            if (patIdxTmp == patIdxStart + 1) {
                // '**/**' situation, so skip one
                patIdxStart++;
                continue;
            }
            // Find the pattern between padIdxStart & padIdxTmp in str between
            // strIdxStart & strIdxEnd
            int patLength = (patIdxTmp - patIdxStart - 1);
            int strLength = (strIdxEnd - strIdxStart + 1);
            int foundIdx = -1;
            strLoop:
            for (int i = 0; i <= strLength - patLength; i++) {
                for (int j = 0; j < patLength; j++) {
                    String subPat = tokenizedPattern[patIdxStart + j + 1];
                    String subStr = strDirs[strIdxStart + i + j];
                    if (!match(subPat, subStr, isCaseSensitive)) {
                        continue strLoop;
                    }
                }

                foundIdx = strIdxStart + i;
                break;
            }

            if (foundIdx == -1) {
                return false;
            }

            patIdxStart = patIdxTmp;
            strIdxStart = foundIdx + patLength;
        }

        for (int i = patIdxStart; i <= patIdxEnd; i++) {
            if (!tokenizedPattern[i].equals(DEEP_TREE_MATCH)) {
                return false;
            }
        }

        return true;
    }
850280
public static Path pathForRelativeFilepath(
            final String filepath,
            final String separator
    )
    {
        String[] comps = filepath.split(Pattern.quote(separator));
        return PathUtil.pathFromComponents(comps);
    }
76946
private static URL makeURLFromFilespec(final String filespec) throws IOException {
        String decoded = URLDecoder.decode(filespec, "UTF-8");
        File file = new File(decoded);
        // make sure it is canonical (no ../ and such)
        file = file.getCanonicalFile();

        return file.toURI().toURL();
    }
1236790
@Nonnull
    public static String getFileSeparatorOnRemote(@Nonnull FilePath filePath) {
        int indexOfSlash = filePath.getRemote().indexOf('/');
        int indexOfBackSlash = filePath.getRemote().indexOf('\\');
        if (indexOfSlash == -1) {
            return "\\";
        } else if (indexOfBackSlash == -1) {
            return "/";
        } else if (indexOfSlash < indexOfBackSlash) {
            return "/";
        } else {
            return "\\";
        }
    }
137988
@Nonnull
    public static String standardizeSlashes(@Nonnull final String pPath)
    {
        final String goodSlash = File.separator;
        final String badSlash = File.separatorChar == '/' ? "\\" : "/";
        // The JDK also assumes there are only these two options.
        String result = pPath.replaceAll(Pattern.quote(badSlash), Matcher.quoteReplacement(goodSlash));
        return result;
    }
1222423
public static String getFileAbsoluteUri(String filePath){
		String fileAbsoluteUri = filePath;
		if (!filePath.startsWith("file://")){
			fileAbsoluteUri = "file://".concat(filePath);
		}	
		return fileAbsoluteUri;		
	}
260464
public static String pathInfo(String pathSpec, String path)
    {
        char c = pathSpec.charAt(0);
        
        if (c=='/')
        {
            if (pathSpec.length()==1)
                return null;
            
            if (pathSpec.equals(path))
                return null;
            
            if (pathSpec.endsWith("/*") &&
                pathSpec.regionMatches(0,path,0,pathSpec.length()-2))
            {
                if (path.length()==pathSpec.length()-2)
                    return null;
                return path.substring(pathSpec.length()-2);
            }
        } 
        return null;
    }
249624
public static String verifyReadFile(String filePath){
		if (filePath==null){
			return "The path is null";
		} 

		File dir=new File(filePath);

		return verifyReadFile(dir);			
	}
589447
public SftpFile[] matchRemoteFiles(String remote)
			throws SftpStatusException, SshException {

		String actualDir;
		String actualSearch;
		int fileSeparatorIndex;
		if ((fileSeparatorIndex = remote.lastIndexOf("/")) > -1) {
			actualDir = remote.substring(0, fileSeparatorIndex);
			actualSearch = remote.length() > fileSeparatorIndex + 1 ? remote
					.substring(fileSeparatorIndex + 1) : "";
		} else {
			actualDir = cwd;
			actualSearch = remote;
		}

		SftpFile[] files;
		RegularExpressionMatching matcher;
		switch (RegExpSyntax) {
		case GlobSyntax:
			matcher = new GlobRegExpMatching();
			files = ls(actualDir);
			break;
		case Perl5Syntax:
			matcher = new Perl5RegExpMatching();
			files = ls(actualDir);
			break;
		default:
			matcher = new NoRegExpMatching();
			files = new SftpFile[1];
			String actual = resolveRemotePath(remote);
			files[0] = getSubsystemChannel().getFile(actual);
		}

		return matcher.matchFilesWithPattern(files, actualSearch);
	}
395198
protected String adaptFilePath(String filePath) {
        // Convert windows file path to target FS
        String targetPath = filePath.replaceAll("\\\\", volumeType.getSeparator());

        return targetPath;
    }
201515
public String[] matchFileNamesWithPattern(File[] files,
			String fileNameRegExp) throws SshException {
		// set up variables for regexp matching
		Pattern mpattern = null;
		PatternCompiler aPCompiler = new Perl5Compiler();
		PatternMatcher aPerl5Matcher = new Perl5Matcher();
		// Attempt to compile the pattern. If the pattern is not valid,
		// throw exception
		try {
			mpattern = aPCompiler.compile(fileNameRegExp);
		} catch (MalformedPatternException e) {
			throw new SshException("Invalid regular expression:"
					+ e.getMessage(), SshException.BAD_API_USAGE);
		}

		Vector<String> matchedNames = new Vector<String>();

		for (int i = 0; i < files.length; i++) {
			if ((!files[i].getName().equals("."))
					&& (!files[i].getName().equals(".."))
					&& (!files[i].isDirectory())) {
				if (aPerl5Matcher.matches(files[i].getName(), mpattern)) {
					// call get for each match, passing true, so that it doesnt
					// repeat the search
					matchedNames.addElement(files[i].getName());
				}
			}
		}

		// return (String[]) matchedNames.toArray(new String[0]);
		String[] matchedNamesStrings = new String[matchedNames.size()];
		matchedNames.copyInto(matchedNamesStrings);
		return matchedNamesStrings;
	}
962629
public static File[] findMatches( File directory , String regex ) {
		final Pattern p = Pattern.compile(regex); // careful: could also throw an exception!
		return directory.listFiles(file -> p.matcher(file.getName()).matches());
	}
548884
public static File[] getFilesListByExtention( String folderPath, final String ext ) {
        File[] files = new File(folderPath).listFiles(new FilenameFilter(){
            public boolean accept( File dir, String name ) {
                return name.endsWith(ext);
            }
        });
        return files;
    }
440887
@Override
    public boolean matches(Source src) {
        String name = src.getOrigin().getName().toLowerCase();
        String[] extensions = getInputFileExtensions();
        if (extensions.length == 1) {
            return FilenameUtils.isExtension(name, extensions[0]);
        }

        return FilenameUtils.isExtension(name, extensions);
    }
171296
function buildRegExps(basePath, dirPaths) {
  return dirPaths.map(folderPath =>
    // Babel cares about windows/unix paths since v7b44
    // https://github.com/babel/babel/issues/8184
    // basePath + path.sep + dirPath/dirRegex
    // /home/name/webroot/js + / + relative/path/to/exclude
    // c:\home\name\webroot\js + \ + relative\path\to\exclude
    folderPath instanceof RegExp
      ? new RegExp(
          `^${escapeRegExp(path.resolve(basePath, '.') + path.sep)}${
            folderPath.source // This is actual regex, don't escape it
          }`,
          folderPath.flags,
        )
      : new RegExp('^' + escapeRegExp(path.resolve(basePath, folderPath))),
  );
}