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

The following examples show how to use org.apache.oro.text.regex.Perl5Matcher. 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: 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 #2
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 #3
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 #4
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 #5
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 #6
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 #7
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 #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: 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 #10
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 #11
Source File: Regexp.java    From scipio-erp with Apache License 2.0 6 votes vote down vote up
@Override
public void exec(Map<String, Object> inMap, Map<String, Object> results, List<Object> messages, Locale locale, ClassLoader loader) {
    Object obj = inMap.get(fieldName);
    String fieldValue = null;
    try {
        fieldValue = (String) ObjectType.simpleTypeConvert(obj, "String", null, locale);
    } catch (GeneralException e) {
        messages.add("Could not convert field value for comparison: " + e.getMessage());
        return;
    }
    if (pattern == null) {
        messages.add("Could not compile regular expression \"" + expr + "\" for validation");
        return;
    }
    PatternMatcher matcher = new Perl5Matcher();
    if (!matcher.matches(fieldValue, pattern)) {
        addMessage(messages, loader, locale);
    }
}
 
Example #12
Source File: SimpleDdlParser.java    From binlake with Apache License 2.0 6 votes vote down vote up
private static DdlResult parseTableName(String matchString, String schmeaName) {
    Perl5Matcher tableMatcher = new Perl5Matcher();
    matchString = matchString + " ";
    if (tableMatcher.matches(matchString, PatternUtils.getPattern(TABLE_PATTERN))) {
        String tableString = tableMatcher.getMatch().group(3);

        tableString = StringUtils.removeEnd(tableString, ";");
        tableString = StringUtils.removeEnd(tableString, "(");
        tableString = StringUtils.trim(tableString);
        // 特殊处理引号`
        tableString = removeEscape(tableString);
        // 处理schema.table的写法
        String names[] = StringUtils.split(tableString, ".");
        if (names != null && names.length > 1) {
            return new DdlResult(removeEscape(names[0]), removeEscape(names[1]));
        } else {
            return new DdlResult(schmeaName, removeEscape(names[0]));
        }
    }

    return null;
}
 
Example #13
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 #14
Source File: ValidatorUtil.java    From webcurator with Apache License 2.0 6 votes vote down vote up
/**
 * Helper method to validate the specified string does not contain anything other than
 * that specified by the regular expression
 * @param aErrors The errors object to populate
 * @param aValue the string to check
 * @param aRegEx the Perl based regular expression to check the value against
 * @param aErrorCode the error code for getting the i8n failure message
 * @param aValues the list of values to replace in the i8n messages
 * @param aFailureMessage the default error message
 */
public static void validateRegEx(Errors aErrors, String aValue, String aRegEx, String aErrorCode, Object[] aValues, String aFailureMessage) {
    if (aValue != null && aRegEx != null && !aRegEx.equals("") && !aValue.trim().equals("")) {
        Perl5Compiler ptrnCompiler = new Perl5Compiler();
        Perl5Matcher matcher = new Perl5Matcher();
        try {
            Perl5Pattern aCharPattern = (Perl5Pattern) ptrnCompiler.compile(aRegEx);
                            
            if (!matcher.contains(aValue, aCharPattern)) {
                aErrors.reject(aErrorCode, aValues, aFailureMessage);               
                return;
            }
        }
        catch (MalformedPatternException e) {
            LogFactory.getLog(ValidatorUtil.class).fatal("Perl pattern malformed: pattern used was "+aRegEx +" : "+ e.getMessage(), e);
        }           
    }
}
 
Example #15
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 #16
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 #17
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 #18
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 #19
Source File: string.java    From openbd-core with GNU General Public License v3.0 5 votes vote down vote up
public static String escapeHtml(String str) {
	try {
		PatternMatcher matcher = new Perl5Matcher();
		PatternCompiler compiler = new Perl5Compiler();

		Pattern pattern = compiler.compile("&(([a-z][a-zA-Z0-9]*)|(#\\d{2,6});)", Perl5Compiler.CASE_INSENSITIVE_MASK | Perl5Compiler.SINGLELINE_MASK);

		String tmp = Util.substitute(matcher, pattern, new Perl5Substitution("&amp;$1"), str, Util.SUBSTITUTE_ALL);

		return replaceChars(tmp, new char[] { '<', '>', '\"' }, new String[] { "&lt;", "&gt;", "&quot;" });
	} catch (Exception e) {
		return str;
	}// won't happen

}
 
Example #20
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 #21
Source File: JavaSource.java    From yugong with GNU General Public License v2.0 5 votes vote down vote up
public String findFirst(String originalStr, String regex) {
    if (StringUtils.isBlank(originalStr) || StringUtils.isBlank(regex)) {
        return StringUtils.EMPTY;
    }

    PatternMatcher matcher = new Perl5Matcher();
    if (matcher.contains(originalStr, patterns.get(regex))) {
        return StringUtils.trimToEmpty(matcher.getMatch().group(0));
    }
    return StringUtils.EMPTY;
}
 
Example #22
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 #23
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 #24
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 #25
Source File: RegexFunction.java    From canal with Apache License 2.0 5 votes vote down vote up
public AviatorObject call(Map<String, Object> env, AviatorObject arg1, AviatorObject arg2) {
    String pattern = FunctionUtils.getStringValue(arg1, env);
    String text = FunctionUtils.getStringValue(arg2, env);
    Perl5Matcher matcher = new Perl5Matcher();
    boolean isMatch = matcher.matches(text, PatternUtils.getPattern(pattern));
    return AviatorBoolean.valueOf(isMatch);
}
 
Example #26
Source File: SimpleDdlParser.java    From canal with Apache License 2.0 5 votes vote down vote up
private static DdlResult parseDdl(String queryString, String schmeaName, String pattern, int index) {
    Perl5Matcher matcher = new Perl5Matcher();
    if (matcher.matches(queryString, PatternUtils.getPattern(pattern))) {
        DdlResult result = parseTableName(matcher.getMatch().group(index), schmeaName);
        return result != null ? result : new DdlResult(schmeaName); // 无法解析时,直接返回schmea,进行兼容处理
    }

    return null;
}
 
Example #27
Source File: SimpleDdlParser.java    From canal with Apache License 2.0 5 votes vote down vote up
private static boolean isDml(String queryString, String pattern) {
    Perl5Matcher matcher = new Perl5Matcher();
    if (matcher.matches(queryString, PatternUtils.getPattern(pattern))) {
        return true;
    } else {
        return false;
    }
}
 
Example #28
Source File: SimpleDdlParser.java    From canal with Apache License 2.0 5 votes vote down vote up
private static DdlResult parseRename(String queryString, String schmeaName, String pattern) {
    Perl5Matcher matcher = new Perl5Matcher();
    if (matcher.matches(queryString, PatternUtils.getPattern(pattern))) {
        DdlResult orign = parseTableName(matcher.getMatch().group(1), schmeaName);
        DdlResult target = parseTableName(matcher.getMatch().group(2), schmeaName);
        if (orign != null && target != null) {
            return new DdlResult(target.getSchemaName(),
                target.getTableName(),
                orign.getSchemaName(),
                orign.getTableName());
        }
    }

    return null;
}
 
Example #29
Source File: SimpleDdlParser.java    From canal with Apache License 2.0 5 votes vote down vote up
private static DdlResult parseTableName(String matchString, String schmeaName) {
    Perl5Matcher tableMatcher = new Perl5Matcher();
    matchString = matchString + " ";
    if (tableMatcher.matches(matchString, PatternUtils.getPattern(TABLE_PATTERN))) {
        String tableString = tableMatcher.getMatch().group(3);
        if (StringUtils.isEmpty(tableString)) {
            return null;
        }

        tableString = StringUtils.removeEnd(tableString, ";");
        tableString = StringUtils.removeEnd(tableString, "(");
        tableString = StringUtils.trim(tableString);
        // 特殊处理引号`
        tableString = removeEscape(tableString);
        // 处理schema.table的写法
        String names[] = StringUtils.split(tableString, ".");
        if (names.length == 0) {
            return null;
        }

        if (names != null && names.length > 1) {
            return new DdlResult(removeEscape(names[0]), removeEscape(names[1]));
        } else {
            return new DdlResult(schmeaName, removeEscape(names[0]));
        }
    }

    return null;
}
 
Example #30
Source File: RegexFunction.java    From canal with Apache License 2.0 5 votes vote down vote up
public AviatorObject call(Map<String, Object> env, AviatorObject arg1, AviatorObject arg2) {
    String pattern = FunctionUtils.getStringValue(arg1, env);
    String text = FunctionUtils.getStringValue(arg2, env);
    Perl5Matcher matcher = new Perl5Matcher();
    boolean isMatch = matcher.matches(text, PatternUtils.getPattern(pattern));
    return AviatorBoolean.valueOf(isMatch);
}