org.apache.oro.text.regex.Pattern Java Examples

The following examples show how to use org.apache.oro.text.regex.Pattern. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: ListChooseByNameModel.java    From consulo with Apache License 2.0 6 votes vote down vote up
@Nullable
private Pattern getTaskPattern(String pattern) {
  if (!Comparing.strEqual(pattern, myPattern)) {
    myCompiledPattern = null;
    myPattern = pattern;
  }
  if (myCompiledPattern == null) {
    final String regex = "^.*" + NameUtil.buildRegexp(pattern, 0, true, true);

    final Perl5Compiler compiler = new Perl5Compiler();
    try {
      myCompiledPattern = compiler.compile(regex);
    }
    catch (MalformedPatternException ignored) {
    }
  }
  return myCompiledPattern;
}
 
Example #2
Source File: FileUtils.java    From openbd-core with GNU General Public License v3.0 6 votes vote down vote up
private static List<File> listFiles(File dir, Pattern _pattern, boolean _recurse, int listType) {
	File[] files = (_pattern == null ? dir.listFiles() : listFiles(dir, _pattern, listType));
	List<File> filesList = new ArrayList<File>();
	Perl5Matcher matcher = ( _pattern == null ? null : new Perl5Matcher() );

	if (files != null) {
		for (int i = 0; i < files.length; i++) {
			boolean isDir = files[i].isDirectory();

			if (isDir && _recurse) {
				filesList.addAll(listFiles(files[i], _pattern, _recurse, listType));
			}

			if ((listType == LIST_TYPE_DIR && !isDir) || (listType == LIST_TYPE_FILE && isDir))
				continue;

			if ( _pattern == null || matcher.matches( files[i].getName(), _pattern ) ){
				filesList.add(files[i]);
			}
		}
	}
	return filesList;
}
 
Example #3
Source File: FileUtils.java    From openbd-core with GNU General Public License v3.0 6 votes vote down vote up
private static List<String> listFilenames(File dir, String _parentDir, Pattern _pattern, boolean _recurse, int listType) {
	File[] files = (_pattern == null ? dir.listFiles() : listFiles(dir, _pattern, listType));
	List<String> filesList = new ArrayList<String>();

	if (files != null) {
		for (int i = 0; i < files.length; i++) {
			boolean isDir = files[i].isDirectory();

			if (isDir && _recurse) {
				filesList.addAll(listFilenames(files[i], _parentDir + files[i].getName() + "/", _pattern, _recurse, listType));
			}

			if ((listType == LIST_TYPE_DIR && !isDir) || (listType == LIST_TYPE_FILE && isDir))
				continue;

			
			if (_pattern == null || listType == LIST_TYPE_ALL ) {
				filesList.add(_parentDir + files[i].getName());
			}
		}
	}
	return filesList;
}
 
Example #4
Source File: reReplace.java    From openbd-core with GNU General Public License v3.0 6 votes vote down vote up
protected String doRereplace( String _theString, String _theRE, String _theSubstr, boolean _casesensitive, boolean _replaceAll ) throws cfmRunTimeException{
	int replaceCount = _replaceAll ? Util.SUBSTITUTE_ALL : 1; 
	PatternMatcher matcher = new Perl5Matcher();
	Pattern pattern = null;
	PatternCompiler compiler = new Perl5Compiler();
   
	try {
		if ( _casesensitive ){
			pattern = compiler.compile( _theRE, Perl5Compiler.SINGLELINE_MASK );
		}else{
			pattern = compiler.compile( _theRE, Perl5Compiler.CASE_INSENSITIVE_MASK | Perl5Compiler.SINGLELINE_MASK );
		}
		
	} catch(MalformedPatternException e){ // definitely should happen since regexp is hardcoded
		cfCatchData catchD = new cfCatchData();
		catchD.setType( "Function" );
		catchD.setMessage( "Internal Error" );
		catchD.setDetail( "Invalid regular expression ( " + _theRE + " )" );
		throw new cfmRunTimeException( catchD );
	}

	// Perform substitution and print result.
	return Util.substitute(matcher, pattern, new Perl5Substitution( processSubstr( _theSubstr ) ), _theString, replaceCount );
}
 
Example #5
Source File: JMeterProxyControl.java    From jsflight with Apache License 2.0 6 votes vote down vote up
private boolean matchesPatterns(String url, CollectionProperty patterns)
{
    for (JMeterProperty jMeterProperty : patterns)
    {
        String item = jMeterProperty.getStringValue();
        try
        {
            Pattern pattern = JMeterUtils.getPatternCache().getPattern(item,
                    Perl5Compiler.READ_ONLY_MASK | Perl5Compiler.SINGLELINE_MASK);
            if (JMeterUtils.getMatcher().matches(url, pattern))
            {
                return true;
            }
        }
        catch (MalformedCachePatternException e)
        {
            LOG.warn("Skipped invalid pattern: " + item, e);
        }
    }
    return false;
}
 
Example #6
Source File: PatternFactory.java    From scipio-erp with Apache License 2.0 6 votes vote down vote up
/**
 * Compiles and caches a Perl5 regexp pattern for the given string pattern.
 * This would be of no benefits (and may bloat memory usage) if stringPattern is never the same.
 * @param stringPattern a Perl5 pattern string
 * @param caseSensitive case sensitive true/false
 * @return a <code>Pattern</code> instance for the given string pattern
 * @throws MalformedPatternException
 */

public static Pattern createOrGetPerl5CompiledPattern(String stringPattern, boolean caseSensitive) throws MalformedPatternException {
    Pattern pattern = compiledPerl5Patterns.get(stringPattern);
    if (pattern == null) {
        Perl5Compiler compiler = new Perl5Compiler();
        if (caseSensitive) {
            pattern = compiler.compile(stringPattern, Perl5Compiler.READ_ONLY_MASK); // READ_ONLY_MASK guarantees immutability
        } else {
            pattern = compiler.compile(stringPattern, Perl5Compiler.CASE_INSENSITIVE_MASK | Perl5Compiler.READ_ONLY_MASK);
        }
        pattern = compiledPerl5Patterns.putIfAbsentAndGet(stringPattern, pattern);
        if (Debug.verboseOn()) {
            Debug.logVerbose("Compiled and cached the pattern: '" + stringPattern, module);
        }
    }
    return pattern;
}
 
Example #7
Source File: EntityComparisonOperator.java    From scipio-erp with Apache License 2.0 6 votes vote down vote up
public static Pattern makeOroPattern(String sqlLike) {
    Perl5Util perl5Util = new Perl5Util();
    try {
        sqlLike = perl5Util.substitute("s/([$^.+*?])/\\\\$1/g", sqlLike);
        sqlLike = perl5Util.substitute("s/%/.*/g", sqlLike);
        sqlLike = perl5Util.substitute("s/_/./g", sqlLike);
    } catch (Throwable t) {
        String errMsg = "Error in ORO pattern substitution for SQL like clause [" + sqlLike + "]: " + t.toString();
        Debug.logError(t, errMsg, module);
        throw new IllegalArgumentException(errMsg);
    }
    try {
        return PatternFactory.createOrGetPerl5CompiledPattern(sqlLike, true);
    } catch (MalformedPatternException e) {
        Debug.logError(e, module);
    }
    return null;
}
 
Example #8
Source File: RegxpContain.java    From anyline with Apache License 2.0 6 votes vote down vote up
/** 
 * 提取子串 
 * @param src		输入字符串  src		输入字符串
 * @param regx		表达式  regx		表达式
 * @param idx		指定提取位置  idx		指定提取位置
 * @return return
 */ 
public List<String> fetch(String src, String regx, int idx) throws Exception{ 
	List<String> list = new ArrayList<String>(); 
	 
	try{ 
		Pattern pattern = patternCompiler.compile(regx, Perl5Compiler.CASE_INSENSITIVE_MASK); 
		PatternMatcher matcher = new Perl5Matcher(); 
		PatternMatcherInput input = new PatternMatcherInput(src); 
		 
		while(matcher.contains(input, pattern)){ 
			MatchResult matchResult = matcher.getMatch(); 
			list.add(matchResult.group(idx)); 
		} 
	}catch(Exception e){ 
		log.error("[提取异常][src:{}][reg:{}]", src, regx);
		e.printStackTrace(); 
		throw e; 
	} 
	return list; 
}
 
Example #9
Source File: RegxpContain.java    From anyline with Apache License 2.0 6 votes vote down vote up
/** 
 * 提取子串 
 * @param src	输入字符串  src	输入字符串
 * @param regx	表达式  regx	表达式
 * @return return
 */ 
public List<List<String>> fetchs(String src, String regx){ 
	List<List<String>> list = new ArrayList<List<String>>(); 
	try{ 
		Pattern pattern = patternCompiler.compile(regx, Perl5Compiler.CASE_INSENSITIVE_MASK); 
		PatternMatcher matcher = new Perl5Matcher(); 
		PatternMatcherInput input = new PatternMatcherInput(src); 
		while(matcher.contains(input, pattern)){ 
			MatchResult matchResult = matcher.getMatch(); 
			int groups = matchResult.groups(); 
			List<String> item = new ArrayList<String>(); 
			for(int i=0; i<groups; i++){ 
				item.add(matchResult.group(i)); 
			} 
			list.add(item); 
		} 
	}catch(Exception e){
		log.error("[提取异常][src:{}][reg:{}]", src, regx);
		e.printStackTrace(); 
	} 
	return list; 
}
 
Example #10
Source File: RegularContain.java    From anyline with Apache License 2.0 6 votes vote down vote up
/** 
 * 提取子串 
 * @param src		输入字符串  src		输入字符串
 * @param regx		表达式  regx		表达式
 * @param idx		指定提取位置  idx		指定提取位置
 * @return return
 */ 
public List<String> fetch(String src, String regx, int idx) throws Exception{ 
	List<String> list = new ArrayList<String>(); 
	 
	try{ 
		Pattern pattern = patternCompiler.compile(regx, Perl5Compiler.CASE_INSENSITIVE_MASK); 
		PatternMatcher matcher = new Perl5Matcher(); 
		PatternMatcherInput input = new PatternMatcherInput(src); 
		 
		while(matcher.contains(input, pattern)){ 
			MatchResult matchResult = matcher.getMatch(); 
			list.add(matchResult.group(idx)); 
		} 
	}catch(Exception e){
		log.error("[提取异常][src:{}][reg:{}]", src, regx);
		if(ConfigTable.isDebug() && log.isWarnEnabled()){
			e.printStackTrace();
		} 
		throw e; 
	} 
	return list; 
}
 
Example #11
Source File: RegularMatchPrefix.java    From anyline with Apache License 2.0 6 votes vote down vote up
/** 
 * 提取子串 
 * @param src		输入字符串  src		输入字符串
 * @param regx		表达式  regx		表达式
 * @param idx		指定提取位置  idx		指定提取位置
 * @return return
 */ 
public List<String> fetch(String src, String regx, int idx){ 
	List<String> list = new ArrayList<String>(); 
	 
	try{ 
		Pattern pattern = patternCompiler.compile(regx, Perl5Compiler.CASE_INSENSITIVE_MASK); 
		PatternMatcher matcher = new Perl5Matcher(); 
		PatternMatcherInput input = new PatternMatcherInput(src); 
		while(matcher.matchesPrefix(input, pattern)){ 
			MatchResult matchResult = matcher.getMatch(); 
			list.add(matchResult.group(idx)); 
		} 
	}catch(Exception e){ 
		if(ConfigTable.isDebug() && log.isWarnEnabled()){
			e.printStackTrace();
		} 
	} 
	return list; 
}
 
Example #12
Source File: RegularMatchPrefix.java    From anyline with Apache License 2.0 6 votes vote down vote up
/** 
 * 提取子串 
 * @param src	输入字符串  src	输入字符串
 * @param regx	表达式  regx	表达式
 * @return return
 */ 
public List<List<String>> fetchs(String src, String regx){ 
	List<List<String>> list = new ArrayList<List<String>>(); 
	try{ 
		Pattern pattern = patternCompiler.compile(regx, Perl5Compiler.CASE_INSENSITIVE_MASK); 
		PatternMatcher matcher = new Perl5Matcher(); 
		PatternMatcherInput input = new PatternMatcherInput(src); 
		while(matcher.matchesPrefix(input, pattern)){ 
			MatchResult matchResult = matcher.getMatch(); 
			int groups = matchResult.groups(); 
			List<String> item = new ArrayList<String>(); 
			for(int i=0; i<=groups; i++){ 
				item.add(matchResult.group(i)); 
			} 
			list.add(item); 
		} 
	}catch(Exception e){ 
		if(ConfigTable.isDebug() && log.isWarnEnabled()){
			e.printStackTrace();
		} 
	} 
	return list; 
}
 
Example #13
Source File: RegularMatch.java    From anyline with Apache License 2.0 6 votes vote down vote up
/** 
 * 提取子串 
 * @param src	输入字符串  src	输入字符串
 * @param regx	表达式  regx	表达式
 * @return return
 */ 
public List<List<String>> fetchs(String src, String regx){ 
	List<List<String>> list = new ArrayList<List<String>>(); 
	try{ 
		Pattern pattern = patternCompiler.compile(regx, Perl5Compiler.DEFAULT_MASK); 
		PatternMatcher matcher = new Perl5Matcher(); 
		PatternMatcherInput input = new PatternMatcherInput(src); 
		while(matcher.matches(input, pattern)){ 
			MatchResult matchResult = matcher.getMatch(); 
			int groups = matchResult.groups(); 
			List<String> item = new ArrayList<String>(); 
			for(int i=0; i<=groups; i++){ 
				item.add(matchResult.group(i)); 
			} 
			list.add(item); 
		} 
	}catch(Exception e){ 
		if(ConfigTable.isDebug() && log.isWarnEnabled()){
			e.printStackTrace();
		} 
	} 
	return list; 
}
 
Example #14
Source File: RegularUtil.java    From anyline with Apache License 2.0 6 votes vote down vote up
/** 
 * 字符串下标 regx在src中首次出现的位置 
 * @param src     src
 * @param regx    regx
 * @param begin   有效开始位置 
 * @return return
 */ 
public static int indexOf(String src, String regx, int begin){ 
	int idx = -1; 
	try{ 
		PatternCompiler patternCompiler = new Perl5Compiler(); 
		Pattern pattern = patternCompiler.compile(regx, Perl5Compiler.CASE_INSENSITIVE_MASK); 
		PatternMatcher matcher = new Perl5Matcher(); 
		PatternMatcherInput input = new PatternMatcherInput(src); 
		 
		while(matcher.contains(input, pattern)){ 
			MatchResult matchResult = matcher.getMatch(); 
			int tmp = matchResult.beginOffset(0); 
			if(tmp >= begin){//匹配位置从begin开始 
				idx = tmp; 
				break; 
			} 
		} 
	}catch(Exception e){
		log.error("[提取异常][src:{}][regx:{}]", src, regx); 
		e.printStackTrace();
	} 
	return idx; 
}
 
Example #15
Source File: RegularContain.java    From anyline with Apache License 2.0 6 votes vote down vote up
/** 
 * 提取子串 
 * @param src	输入字符串  src	输入字符串
 * @param regx	表达式  regx	表达式
 * @return return
 */ 
public List<List<String>> fetchs(String src, String regx){ 
	List<List<String>> list = new ArrayList<List<String>>(); 
	try{ 
		Pattern pattern = patternCompiler.compile(regx, Perl5Compiler.CASE_INSENSITIVE_MASK); 
		PatternMatcher matcher = new Perl5Matcher(); 
		PatternMatcherInput input = new PatternMatcherInput(src); 
		while(matcher.contains(input, pattern)){ 
			MatchResult matchResult = matcher.getMatch(); 
			int groups = matchResult.groups(); 
			List<String> item = new ArrayList<String>(); 
			for(int i=0; i<groups; i++){ 
				item.add(matchResult.group(i)); 
			} 
			list.add(item); 
		} 
	}catch(Exception e){ 
		log.error("[提取异常][src:{}][reg:{}]", src, regx);
		if(ConfigTable.isDebug() && log.isWarnEnabled()){
			e.printStackTrace();
		} 
	} 
	return list; 
}
 
Example #16
Source File: RegularMatch.java    From anyline with Apache License 2.0 6 votes vote down vote up
/** 
 * 提取子串 
 * @param src		输入字符串  src		输入字符串
 * @param regx		表达式  regx		表达式
 * @param idx		指定提取位置  idx		指定提取位置
 * @return return
 */ 
public List<String> fetch(String src, String regx, int idx){ 
	List<String> list = new ArrayList<String>(); 
	 
	try{ 
		Pattern pattern = patternCompiler.compile(regx, Perl5Compiler.DEFAULT_MASK); 
		PatternMatcher matcher = new Perl5Matcher(); 
		PatternMatcherInput input = new PatternMatcherInput(src); 
		while(matcher.matches(input, pattern)){ 
			MatchResult matchResult = matcher.getMatch(); 
			list.add(matchResult.group(idx)); 
		} 
	}catch(Exception e){ 
		if(ConfigTable.isDebug() && log.isWarnEnabled()){
			e.printStackTrace();
		} 
	} 
	return list; 
}
 
Example #17
Source File: RegexpStressTest.java    From common-utils with GNU General Public License v2.0 5 votes vote down vote up
public void run(int loop) {
    PatternMatcher matcher = new Perl5Matcher();

    for (int i = 0; i < loop; i++) {
        for (Pattern pattern : patterns) {
            for (String value : data) {
                matcher.contains(value, pattern);
            }
        }
    }
}
 
Example #18
Source File: string.java    From openbd-core with GNU General Public License v3.0 5 votes vote down vote up
public static boolean regexMatches(String str, String re) throws MalformedPatternException {
	PatternMatcher matcher = new Perl5Matcher();
	PatternCompiler compiler = new Perl5Compiler();
	PatternMatcherInput input = new PatternMatcherInput(str);

	Pattern pattern = compiler.compile(re, Perl5Compiler.SINGLELINE_MASK);
	return matcher.matches(input, pattern);
}
 
Example #19
Source File: ListChooseByNameModel.java    From consulo with Apache License 2.0 5 votes vote down vote up
public boolean matches(@Nonnull final String name, @Nonnull final String pattern) {
  final Pattern compiledPattern = getTaskPattern(pattern);
  if (compiledPattern == null) {
    return false;
  }

  return new Perl5Matcher().matches(name, compiledPattern);
}
 
Example #20
Source File: cfCACHE.java    From openbd-core with GNU General Public License v3.0 5 votes vote down vote up
private static String escapeExpireUrl(String expireURL){
Perl5Compiler 			compiler 	= new Perl5Compiler();
Perl5Matcher				matcher 	= new Perl5Matcher();
Pattern 						pattern 	= null;

try{
	pattern		= compiler.compile( "([+?.])" );
  expireURL = Util.substitute(matcher, pattern, new Perl5Substitution( "\\\\$1" ), expireURL, Util.SUBSTITUTE_ALL );
  return com.nary.util.string.replaceString(expireURL,"*",".*");
}catch(Exception E){
	return null;
}
}
 
Example #21
Source File: Perl5RegExpMatching.java    From j2ssh-maverick with GNU Lesser General Public License v3.0 5 votes vote down vote up
/**
 * compiles fileNameRegExp into a regular expression and pattern matches on
 * each file's name, and returns those that match.
 * 
 * @param files
 * @param fileNameRegExp
 * 
 * @return String[] of file names that match the expresion.
 */
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;
}
 
Example #22
Source File: Perl5RegExpMatching.java    From j2ssh-maverick with GNU Lesser General Public License v3.0 5 votes vote down vote up
/**
 * 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.
 */
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;
}
 
Example #23
Source File: GlobRegExpMatching.java    From j2ssh-maverick with GNU Lesser General Public License v3.0 5 votes vote down vote up
/**
 * compiles fileNameRegExp into a regular expression and pattern matches on
 * each file's name, and returns those that match.
 * 
 * @param files
 * @param fileNameRegExp
 * 
 * @return String[] of files that match the expresion.
 */
public String[] matchFileNamesWithPattern(File[] files,
		String fileNameRegExp) throws SshException {
	// set up variables for regexp matching
	Pattern mpattern = null;
	PatternCompiler aGCompiler = new GlobCompiler();
	PatternMatcher aPerl5Matcher = new Perl5Matcher();
	// Attempt to compile the pattern. If the pattern is not valid,
	// throw exception
	try {
		mpattern = aGCompiler.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(".."))) {
			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].getAbsolutePath());
			}
		}
	}

	// return (String[]) matchedNames.toArray(new String[0]);
	String[] matchedNamesStrings = new String[matchedNames.size()];
	matchedNames.copyInto(matchedNamesStrings);
	return matchedNamesStrings;
}
 
Example #24
Source File: GlobRegExpMatching.java    From j2ssh-maverick with GNU Lesser General Public License v3.0 5 votes vote down vote up
/**
 * 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.
 */
public SftpFile[] matchFilesWithPattern(SftpFile[] files,
		String fileNameRegExp) throws SftpStatusException, SshException {
	// set up variables for regexp matching
	Pattern mpattern = null;
	PatternCompiler aGCompiler = new GlobCompiler();
	PatternMatcher aPerl5Matcher = new Perl5Matcher();
	// Attempt to compile the pattern. If the pattern is not valid,
	// throw exception
	try {
		mpattern = aGCompiler.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;
}
 
Example #25
Source File: RegexpStressTest.java    From common-utils with GNU General Public License v2.0 5 votes vote down vote up
public OroTester() throws Exception {
    patterns = new Pattern[exps.length];

    for (int i = 0; i < patterns.length; i++) {
        patterns[i] =
                new Perl5Compiler().compile(exps[i], Perl5Compiler.CASE_INSENSITIVE_MASK
                        | Perl5Compiler.READ_ONLY_MASK);
    }
}
 
Example #26
Source File: RegexpStressTest.java    From common-utils with GNU General Public License v2.0 5 votes vote down vote up
public void warmUp() {
    PatternMatcher matcher = new Perl5Matcher();
    int matchedCount = 0;

    for (Pattern pattern : patterns) {
        for (String value : data) {
            if (matcher.contains(value, pattern)) {
                matchedCount++;
            }
        }
    }

    assertEquals(RegexpStressTest.this.matchedCount, matchedCount);
}
 
Example #27
Source File: JSONPathAssertion.java    From jmeter-plugins with Apache License 2.0 5 votes vote down vote up
private boolean isEquals(Object subj) {
    String str = JSONPathExtractor.objectToString(subj);
    if (isUseRegex()) {
        Pattern pattern = JMeterUtils.getPatternCache().getPattern(getExpectedValue());
        return JMeterUtils.getMatcher().matches(str, pattern);
    } else {
        return str.equals(getExpectedValue());
    }
}
 
Example #28
Source File: RegexpStressTest.java    From common-utils with GNU General Public License v2.0 5 votes vote down vote up
public JdkRegexTester() throws Exception {
    patterns = new java.util.regex.Pattern[exps.length];

    for (int i = 0; i < patterns.length; i++) {
        patterns[i] = java.util.regex.Pattern.compile(exps[i], java.util.regex.Pattern.CASE_INSENSITIVE);
    }
}
 
Example #29
Source File: RegexpStressTest.java    From common-utils with GNU General Public License v2.0 5 votes vote down vote up
public void run(int loop) {
    for (int i = 0; i < loop; i++) {
        for (java.util.regex.Pattern pattern : patterns) {
            for (String value : data) {
                pattern.matcher(value).find();
            }
        }
    }
}
 
Example #30
Source File: RegexpStressTest.java    From common-utils with GNU General Public License v2.0 5 votes vote down vote up
public void warmUp() {
    int matchedCount = 0;

    for (java.util.regex.Pattern pattern : patterns) {
        for (String value : data) {
            if (pattern.matcher(value).find()) {
                matchedCount++;
            }
        }
    }

    assertEquals(RegexpStressTest.this.matchedCount, matchedCount);
}