code: public SftpFile[] matchFilesWithPattern(SftpFile[] files,
  			String fileNameRegExp) throws SftpStatusException, 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<SftpFile> matchedNames = new Vector<SftpFile>();
  
  		for (int i = 0; i < files.length; i++) {
  			if ((!files[i].getFilename().equals("."))
  					&& (!files[i].getFilename().equals(".."))
  					&& (!files[i].isDirectory())) {
  				if (aPerl5Matcher.matches(files[i].getFilename(), mpattern)) {
  					// call get for each match, passing true, so that it doesnt
  					// repeat the search
  					matchedNames.addElement(files[i]);
  				}
  			}
  		}
  
  		// return (SftpFile[]) matchedNames.toArray(new SftpFile[0]);
  		SftpFile[] matchedNamesSftpFiles = new SftpFile[matchedNames.size()];
  		matchedNames.copyInto(matchedNamesSftpFiles);
  		return matchedNamesSftpFiles;
  	}
docs: compiles fileNameRegExp into a regular expression and pattern matches on
  each file's name, and returns those that match.
  
  @param files
  @param fileNameRegExp
  
  @return SftpFile[] of files that match the expresion.