当前位置: 首页>>代码示例>>Java>>正文


Java PatternMatcher类代码示例

本文整理汇总了Java中org.apache.oro.text.regex.PatternMatcher的典型用法代码示例。如果您正苦于以下问题:Java PatternMatcher类的具体用法?Java PatternMatcher怎么用?Java PatternMatcher使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


PatternMatcher类属于org.apache.oro.text.regex包,在下文中一共展示了PatternMatcher类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: check

import org.apache.oro.text.regex.PatternMatcher; //导入依赖的package包/类
public boolean check(String action, String method) {
    if (!StringUtil.isBlank(action)) {
        PatternMatcher matcher = new Perl5Matcher();
        Iterator<ActionPatternHolder> iter = actionPatternList.iterator();
        while (iter.hasNext()) {
            ActionPatternHolder holder = (ActionPatternHolder) iter.next();
            if (StringUtils.isNotEmpty(action) && matcher.matches(action, holder.getActionPattern())
                && StringUtils.isNotEmpty(method) && matcher.matches(method, holder.getMethodPattern())) {
                if (logger.isDebugEnabled()) {
                    logger.debug("Candidate is: '" + action + "|" + method + "'; pattern is "
                                 + holder.getActionName() + "|" + holder.getMethodName() + "; matched=true");
                }
                return true;
            }
        }
    }

    return false;
}
 
开发者ID:luoyaogui,项目名称:otter-G,代码行数:20,代码来源:ActionProtectedImpl.java

示例2: findFirst

import org.apache.oro.text.regex.PatternMatcher; //导入依赖的package包/类
public static 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;
}
 
开发者ID:luoyaogui,项目名称:otter-G,代码行数:12,代码来源:RegexUtils.java

示例3: check

import org.apache.oro.text.regex.PatternMatcher; //导入依赖的package包/类
public boolean check(String requestUrl) {
    if (StringUtils.isBlank(requestUrl)) {
        return false;
    }

    if (logger.isDebugEnabled()) {
        logger.debug("Converted URL to lowercase, from: '" + requestUrl + "'; to: '" + requestUrl + "'");
    }

    PatternMatcher matcher = new Perl5Matcher();

    Iterator<URLPatternHolder> iter = urlProtectedList.iterator();

    while (iter.hasNext()) {
        URLPatternHolder holder = (URLPatternHolder) iter.next();

        if (matcher.matches(requestUrl, holder.getCompiledPattern())) {
            if (logger.isDebugEnabled()) {
                logger.debug("Candidate is: '" + requestUrl + "'; pattern is "
                             + holder.getCompiledPattern().getPattern() + "; matched=true");
            }
            return true;
        }
    }
    return false;
}
 
开发者ID:luoyaogui,项目名称:otter-G,代码行数:27,代码来源:URLProtectedImpl.java

示例4: exec

import org.apache.oro.text.regex.PatternMatcher; //导入依赖的package包/类
@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);
    }
}
 
开发者ID:ilscipio,项目名称:scipio-erp,代码行数:20,代码来源:Regexp.java

示例5: fetch

import org.apache.oro.text.regex.PatternMatcher; //导入依赖的package包/类
/**
 * 提取子串
 * @param src	输入字符串
 * @param regx	表达式
 * @return
 */
public List<List<String>> fetch(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.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()){
			e.printStackTrace();
		}
	}
	return list;
}
 
开发者ID:anylineorg,项目名称:anyline,代码行数:29,代码来源:RegularMatch.java

示例6: indexOf

import org.apache.oro.text.regex.PatternMatcher; //导入依赖的package包/类
/**
 * 字符串下标 regx在src中首次出现的位置
 * @param src   
 * @param regx  
 * @param idx   有效开始位置
 * @return
 * @throws Exception
 */
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("fetch(String,String):\n"+"src="+src+"\regx="+regx+"\n"+e);
		if(ConfigTable.isDebug()){
			e.printStackTrace();
		}
	}
	return idx;
}
 
开发者ID:anylineorg,项目名称:anyline,代码行数:33,代码来源:RegularUtil.java

示例7: fetch

import org.apache.oro.text.regex.PatternMatcher; //导入依赖的package包/类
/**
 * 提取子串
 * @param src	输入字符串
 * @param regx	表达式
 * @return
 */
public List<List<String>> fetch(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()){
			e.printStackTrace();
		}
	}
	return list;
}
 
开发者ID:anylineorg,项目名称:anyline,代码行数:29,代码来源:RegularMatchPrefix.java

示例8: fetch

import org.apache.oro.text.regex.PatternMatcher; //导入依赖的package包/类
/**
 * 提取子串
 * @param src	输入字符串
 * @param regx	表达式
 * @return
 */
public List<List<String>> fetch(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("fetch(String,String):\n"+"src="+src+"\regx="+regx+"\n"+e);
		if(ConfigTable.isDebug()){
			e.printStackTrace();
		}
	}
	return list;
}
 
开发者ID:anylineorg,项目名称:anyline,代码行数:30,代码来源:RegularContain.java

示例9: fetch

import org.apache.oro.text.regex.PatternMatcher; //导入依赖的package包/类
/**
 * 提取子串
 * @param src	输入字符串
 * @param regx	表达式
 * @return
 */
public List<List<String>> fetch(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("fetch(String,String):\n"+"src="+src+"\regx="+regx+"\n"+e);
	}
	return list;
}
 
开发者ID:anylineorg,项目名称:anyline,代码行数:27,代码来源:RegxpContain.java

示例10: doRereplace

import org.apache.oro.text.regex.PatternMatcher; //导入依赖的package包/类
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 );
}
 
开发者ID:OpenBD,项目名称:openbd-core,代码行数:25,代码来源:reReplace.java

示例11: realizeTemplate

import org.apache.oro.text.regex.PatternMatcher; //导入依赖的package包/类
/**
 * Convert a template query by replacing the template areas with
 * the given replacement string, which is generally a column name.
 */
private static String realizeTemplate( String template, String replacement ) {
    String output = "";
    PatternCompiler compiler = new Perl5Compiler();
    PatternMatcher matcher = new Perl5Matcher();

    try {
        Pattern pattern = compiler.compile( kTemplateVariable );
        output = Util.substitute( matcher, pattern, new StringSubstitution(replacement), template, Util.SUBSTITUTE_ALL );
    }
    catch( MalformedPatternException mpe ) {
        System.err.println( "TextConverter.realizeTemplate(): " + mpe );
    }

    return( output );
}
 
开发者ID:tair,项目名称:tairwebapp,代码行数:20,代码来源:TextConverter.java

示例12: parseParts

import org.apache.oro.text.regex.PatternMatcher; //导入依赖的package包/类
/**
 * @return Collection of strings extracted from input 'term', respecting quoted regions.
 * Thus input = "foo 'bar baz' zip" will return "foo", "bar baz", "zip".
 */
private static Collection<String> parseParts( String term )
{
    // first, get all the quoted strings.
    Collection<String> searchParts = new ArrayList<String>();
    String reducedTerm = extractPattern( "'([^']*)'", term, searchParts );
    reducedTerm = extractPattern( "\"([^\"]*)\"", reducedTerm, searchParts );

    // second, get all remaining non-empty terms.
    if( false == reducedTerm.trim().equals( "" ) )
    {
        PatternCompiler compiler = new Perl5Compiler();
        PatternMatcher matcher = new Perl5Matcher();
        try {
            Pattern pattern = compiler.compile( "\\s+" );
            Util.split( searchParts, matcher, pattern, reducedTerm );
        }
        catch( MalformedPatternException mpe ) {
            System.err.println( "TextConverter.parseParts(): " + mpe );
        }
    }

    return( searchParts );
}
 
开发者ID:tair,项目名称:tairwebapp,代码行数:28,代码来源:TextConverter.java

示例13: extractPattern

import org.apache.oro.text.regex.PatternMatcher; //导入依赖的package包/类
/**
 * Given a regular expression, remove matches from the input string and
 * store them in the given Collection. Note: it is assumed that the
 * regular expression has one parenthasized matching group which
 * is the text to be placed in the Collection. Text outside of that
 * group which still matches the regexp is deleted.
 * @return String that is 'input' with all 'regex' matches deleted.
 */
private static String extractPattern(String regex, String input, Collection<String> found) {
    String output = "";
    PatternCompiler compiler = new Perl5Compiler();
    PatternMatcher matcher = new Perl5Matcher();

    try {
        Pattern pattern = compiler.compile(regex);

        PatternMatcherInput matcherInput = new PatternMatcherInput( input );
        while( matcher.contains( matcherInput, pattern ) ) {
            MatchResult result = matcher.getMatch();
            if( result.groups() > 0 ) {
                String sub = result.group( 1 );
                found.add( sub );
            }
        }

        output = Util.substitute( matcher, pattern, new StringSubstitution(), input, Util.SUBSTITUTE_ALL );
    }
    catch( MalformedPatternException mpe ) {
        System.err.println( "TextConverter.extractPattern(): " + mpe );
    }

    return (output);
}
 
开发者ID:tair,项目名称:tairwebapp,代码行数:34,代码来源:TextConverter.java

示例14: parseMode

import org.apache.oro.text.regex.PatternMatcher; //导入依赖的package包/类
/**
 * 解析DataMedia中的namespace和name,支持offer[1-128]分库的定义
 */
public static ModeValue parseMode(String value) {
    PatternMatcher matcher = new Perl5Matcher();
    if (matcher.matches(value, patterns.get(MODE_PATTERN))) {
        MatchResult matchResult = matcher.getMatch();
        String prefix = matchResult.group(1);
        String startStr = matchResult.group(3);
        String ednStr = matchResult.group(4);
        int start = Integer.valueOf(startStr);
        int end = Integer.valueOf(ednStr);
        String postfix = matchResult.group(5);

        List<String> values = new ArrayList<String>();
        for (int i = start; i <= end; i++) {
            StringBuilder builder = new StringBuilder(value.length());
            String str = String.valueOf(i);
            // 处理0001类型
            if (startStr.length() == ednStr.length() && startStr.startsWith("0")) {
                str = StringUtils.leftPad(String.valueOf(i), startStr.length(), '0');
            }

            builder.append(prefix).append(str).append(postfix);
            values.add(builder.toString());
        }
        return new ModeValue(Mode.MULTI, values);
    } else if (isWildCard(value)) {// 通配符支持
        return new ModeValue(Mode.WILDCARD, Arrays.asList(value));
    } else {
        return new ModeValue(Mode.SINGLE, Arrays.asList(value));
    }
}
 
开发者ID:luoyaogui,项目名称:otter-G,代码行数:34,代码来源:ConfigHelper.java

示例15: testWildCard

import org.apache.oro.text.regex.PatternMatcher; //导入依赖的package包/类
@Test
public void testWildCard() {
    PatternMatcher matcher = new Perl5Matcher();

    Pattern pattern = null;
    PatternCompiler pc = new Perl5Compiler();
    try {
        pattern = pc.compile("havana_us_.*", Perl5Compiler.DEFAULT_MASK);
    } catch (MalformedPatternException e) {
        throw new ConfigException(e);
    }
    boolean ismatch = matcher.matches("havana_us_0001", pattern);
    System.out.println(ismatch);
}
 
开发者ID:luoyaogui,项目名称:otter-G,代码行数:15,代码来源:ConfigHelperTest.java


注:本文中的org.apache.oro.text.regex.PatternMatcher类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。