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


Java PatternMatcher.contains方法代码示例

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


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

示例1: 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

示例2: 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

示例3: 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

示例4: 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

示例5: 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

示例6: checkURLforSpiders

import org.apache.oro.text.regex.PatternMatcher; //导入方法依赖的package包/类
/**
 * checks, if the current request comes from a searchbot
 *
 * @param request
 * @return whether the request is from a web searchbot
 */
public static boolean checkURLforSpiders(HttpServletRequest request) {
    boolean result = false;

    String spiderRequest = (String) request.getAttribute("_REQUEST_FROM_SPIDER_");
    if (UtilValidate.isNotEmpty(spiderRequest)) {
        if ("Y".equals(spiderRequest)) {
            return true;
        } else {
            return false;
        }
    } else {
        String initialUserAgent = request.getHeader("User-Agent") != null ? request.getHeader("User-Agent") : "";
        List<String> spiderList = StringUtil.split(UtilProperties.getPropertyValue("url", "link.remove_lsessionid.user_agent_list"), ",");

        if (UtilValidate.isNotEmpty(spiderList)) {
            for (String spiderNameElement : spiderList) {
                Pattern pattern = null;
                try {
                    pattern = PatternFactory.createOrGetPerl5CompiledPattern(spiderNameElement, false);
                } catch (MalformedPatternException e) {
                    Debug.logError(e, module);
                }
                PatternMatcher matcher = new Perl5Matcher();
                if (matcher.contains(initialUserAgent, pattern)) {
                    request.setAttribute("_REQUEST_FROM_SPIDER_", "Y");
                    result = true;
                    break;
                }
            }
        }
    }

    if (!result) {
        request.setAttribute("_REQUEST_FROM_SPIDER_", "N");
    }

    return result;
}
 
开发者ID:ilscipio,项目名称:scipio-erp,代码行数:45,代码来源:UtilHttp.java

示例7: findFirst

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

示例8: match

import org.apache.oro.text.regex.PatternMatcher; //导入方法依赖的package包/类
/**
 * 配置状态
 * @param src
 * @param regx
 * @return
 */
public boolean match(String src, String regx){
	boolean result = false;
	try{
		Pattern pattern = patternCompiler.compile(regx, Perl5Compiler.CASE_INSENSITIVE_MASK);
		PatternMatcher matcher = new Perl5Matcher();
		result = matcher.contains(src, pattern);
	}catch(Exception e){
		result = false;
		if(ConfigTable.isDebug()){
			e.printStackTrace();
		}
	}
	return result;
}
 
开发者ID:anylineorg,项目名称:anyline,代码行数:21,代码来源:RegularContain.java

示例9: match

import org.apache.oro.text.regex.PatternMatcher; //导入方法依赖的package包/类
/**
 * 配置状态
 * @param src
 * @param regx
 * @return
 */
public boolean match(String src, String regx){
	boolean result = false;
	try{
		Pattern pattern = patternCompiler.compile(regx, Perl5Compiler.CASE_INSENSITIVE_MASK);
		PatternMatcher matcher = new Perl5Matcher();
		result = matcher.contains(src, pattern);
	}catch(Exception e){
		result = false;
	}
	return result;
}
 
开发者ID:anylineorg,项目名称:anyline,代码行数:18,代码来源:RegxpContain.java

示例10: initTemplate

import org.apache.oro.text.regex.PatternMatcher; //导入方法依赖的package包/类
private void initTemplate() {
    if (template != null) {
        return;
    }
    // Contains Strings and Integers
    List<Object> combined = new ArrayList<>();
    String rawTemplate = getTemplate();
    PatternMatcher matcher = JMeterUtils.getMatcher();
    Pattern templatePattern = JMeterUtils.getPatternCache().getPattern("\\$(\\d+)\\$"  // $NON-NLS-1$
            , Perl5Compiler.READ_ONLY_MASK
            & Perl5Compiler.SINGLELINE_MASK);
    if (log.isDebugEnabled()) {
        log.debug("Pattern = " + templatePattern.getPattern());
        log.debug("template = " + rawTemplate);
    }
    int beginOffset = 0;
    MatchResult currentResult;
    PatternMatcherInput pinput = new PatternMatcherInput(rawTemplate);
    while(matcher.contains(pinput, templatePattern)) {
        currentResult = matcher.getMatch();
        final int beginMatch = currentResult.beginOffset(0);
        if (beginMatch > beginOffset) { // string is not empty
            combined.add(rawTemplate.substring(beginOffset, beginMatch));
        }
        combined.add(Integer.valueOf(currentResult.group(1)));// add match as Integer
        beginOffset = currentResult.endOffset(0);
    }

    if (beginOffset < rawTemplate.length()) { // trailing string is not empty
        combined.add(rawTemplate.substring(beginOffset, rawTemplate.length()));
    }
    if (log.isDebugEnabled()){
        log.debug("Template item count: "+combined.size());
        for(Object o : combined){
            log.debug(o.getClass().getSimpleName()+" '"+o.toString()+"'");
        }
    }
    template = combined;
}
 
开发者ID:johrstrom,项目名称:cloud-meter,代码行数:40,代码来源:RegexExtractor.java

示例11: generateTemplate

import org.apache.oro.text.regex.PatternMatcher; //导入方法依赖的package包/类
private Object[] generateTemplate(String rawTemplate) {
    List<String> pieces = new ArrayList<>();
    // String or Integer
    List<Object> combined = new LinkedList<>();
    PatternMatcher matcher = JMeterUtils.getMatcher();
    Util.split(pieces, matcher, templatePattern, rawTemplate);
    PatternMatcherInput input = new PatternMatcherInput(rawTemplate);
    boolean startsWith = isFirstElementGroup(rawTemplate);
    if (startsWith) {
        pieces.remove(0);// Remove initial empty entry
    }
    Iterator<String> iter = pieces.iterator();
    while (iter.hasNext()) {
        boolean matchExists = matcher.contains(input, templatePattern);
        if (startsWith) {
            if (matchExists) {
                combined.add(Integer.valueOf(matcher.getMatch().group(1)));
            }
            combined.add(iter.next());
        } else {
            combined.add(iter.next());
            if (matchExists) {
                combined.add(Integer.valueOf(matcher.getMatch().group(1)));
            }
        }
    }
    if (matcher.contains(input, templatePattern)) {
        combined.add(Integer.valueOf(matcher.getMatch().group(1)));
    }
    return combined.toArray();
}
 
开发者ID:johrstrom,项目名称:cloud-meter,代码行数:32,代码来源:RegexFunction.java

示例12: calcuExpressionValue

import org.apache.oro.text.regex.PatternMatcher; //导入方法依赖的package包/类
/**
 * Calculate expression
 * 
 * @param expression:式
 * @return String or Number type
 */
private Object calcuExpressionValue(String expression) {
	log.debug("expression:" + expression);

	if (expression == null || expression.equals(""))
		return true;

	// clear work variable
	tokenList.clear();
	operatorStack.clear();
	paramStack.clear();

	// make token list
	MatchResult matchResult = null;
	PatternMatcherInput matcherInput = new PatternMatcherInput(expression);
	PatternMatcher matcher = new Perl5Matcher();
	int iStart = 0;
	int iEnd = 0;

	while (matcher.contains(matcherInput, regexExpression)) {
		matchResult = matcher.getMatch();

		iStart = matchResult.beginOffset(0);
		iEnd = matchResult.endOffset(0);

		tokenList.add(expression.substring(iStart, iEnd));
	}

	return getSimpleExpressionValue();
}
 
开发者ID:SalamaSoft,项目名称:REST-framework,代码行数:36,代码来源:SimpleExpressionAnalyzer.java

示例13: generateTemplate

import org.apache.oro.text.regex.PatternMatcher; //导入方法依赖的package包/类
private Object[] generateTemplate(String rawTemplate) {
    List<String> pieces = new ArrayList<String>();
    // String or Integer
    List<Object> combined = new LinkedList<Object>();
    PatternMatcher matcher = JMeterUtils.getMatcher();
    Util.split(pieces, matcher, templatePattern, rawTemplate);
    PatternMatcherInput input = new PatternMatcherInput(rawTemplate);
    boolean startsWith = isFirstElementGroup(rawTemplate);
    if (startsWith) {
        pieces.remove(0);// Remove initial empty entry
    }
    Iterator<String> iter = pieces.iterator();
    while (iter.hasNext()) {
        boolean matchExists = matcher.contains(input, templatePattern);
        if (startsWith) {
            if (matchExists) {
                combined.add(Integer.valueOf(matcher.getMatch().group(1)));
            }
            combined.add(iter.next());
        } else {
            combined.add(iter.next());
            if (matchExists) {
                combined.add(Integer.valueOf(matcher.getMatch().group(1)));
            }
        }
    }
    if (matcher.contains(input, templatePattern)) {
        combined.add(Integer.valueOf(matcher.getMatch().group(1)));
    }
    return combined.toArray();
}
 
开发者ID:botelhojp,项目名称:apache-jmeter-2.10,代码行数:32,代码来源:RegexFunction.java

示例14: initTemplate

import org.apache.oro.text.regex.PatternMatcher; //导入方法依赖的package包/类
private void initTemplate() {
    if (template != null) {
        return;
    }
    // Contains Strings and Integers
    List<Object> combined = new ArrayList<Object>();
    String rawTemplate = getTemplate();
    PatternMatcher matcher = JMeterUtils.getMatcher();
    Pattern templatePattern = JMeterUtils.getPatternCache().getPattern("\\$(\\d+)\\$"  // $NON-NLS-1$
            , Perl5Compiler.READ_ONLY_MASK
            & Perl5Compiler.SINGLELINE_MASK);
    if (log.isDebugEnabled()) {
        log.debug("Pattern = " + templatePattern.getPattern());
        log.debug("template = " + rawTemplate);
    }
    int beginOffset = 0;
    MatchResult currentResult;
    PatternMatcherInput pinput = new PatternMatcherInput(rawTemplate);
    while(matcher.contains(pinput, templatePattern)) {
        currentResult = matcher.getMatch();
        final int beginMatch = currentResult.beginOffset(0);
        if (beginMatch > beginOffset) { // string is not empty
            combined.add(rawTemplate.substring(beginOffset, beginMatch));
        }
        combined.add(Integer.valueOf(currentResult.group(1)));// add match as Integer
        beginOffset = currentResult.endOffset(0);
    }

    if (beginOffset < rawTemplate.length()) { // trailing string is not empty
        combined.add(rawTemplate.substring(beginOffset, rawTemplate.length()));
    }
    if (log.isDebugEnabled()){
        log.debug("Template item count: "+combined.size());
        for(Object o : combined){
            log.debug(o.getClass().getSimpleName()+" '"+o.toString()+"'");
        }
    }
    template = combined;
}
 
开发者ID:botelhojp,项目名称:apache-jmeter-2.10,代码行数:40,代码来源:RegexExtractor.java

示例15: getOutlinks

import org.apache.oro.text.regex.PatternMatcher; //导入方法依赖的package包/类
/**
 * Extracts <code>Outlink</code> from given plain text and adds anchor to the
 * extracted <code>Outlink</code>s
 * 
 * @param plainText
 *          the plain text from wich URLs should be extracted.
 * @param anchor
 *          the anchor of the url
 * 
 * @return Array of <code>Outlink</code>s within found in plainText
 */
public static Outlink[] getOutlinks(final String plainText, String anchor,
    Configuration conf) {
  long start = System.currentTimeMillis();
  final List<Outlink> outlinks = new ArrayList<Outlink>();

  try {
    final PatternCompiler cp = new Perl5Compiler();
    final Pattern pattern = cp.compile(URL_PATTERN,
        Perl5Compiler.CASE_INSENSITIVE_MASK | Perl5Compiler.READ_ONLY_MASK
            | Perl5Compiler.MULTILINE_MASK);
    final PatternMatcher matcher = new Perl5Matcher();

    final PatternMatcherInput input = new PatternMatcherInput(plainText);

    MatchResult result;
    String url;

    // loop the matches
    while (matcher.contains(input, pattern)) {
      // if this is taking too long, stop matching
      // (SHOULD really check cpu time used so that heavily loaded systems
      // do not unnecessarily hit this limit.)
      if (System.currentTimeMillis() - start >= 60000L) {
        if (LOG.isWarnEnabled()) {
          LOG.warn("Time limit exceeded for getOutLinks");
        }
        break;
      }
      result = matcher.getMatch();
      url = result.group(0);
      try {
        outlinks.add(new Outlink(url, anchor));
      } catch (MalformedURLException mue) {
        LOG.warn("Invalid url: '" + url + "', skipping.");
      }
    }
  } catch (Exception ex) {
    // if the matcher fails (perhaps a malformed URL) we just log it and move
    // on
    if (LOG.isErrorEnabled()) {
      LOG.error("getOutlinks", ex);
    }
  }

  final Outlink[] retval;

  // create array of the Outlinks
  if (outlinks != null && outlinks.size() > 0) {
    retval = outlinks.toArray(new Outlink[0]);
  } else {
    retval = new Outlink[0];
  }

  return retval;
}
 
开发者ID:jorcox,项目名称:GeoCrawler,代码行数:67,代码来源:OutlinkExtractor.java


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