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


Java PatternMatcher.getMatch方法代码示例

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


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

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

示例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.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

示例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);
		if(ConfigTable.isDebug()){
			e.printStackTrace();
		}
	}
	return list;
}
 
开发者ID:anylineorg,项目名称:anyline,代码行数:30,代码来源:RegularContain.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.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

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

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

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

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

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

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

示例12: 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:yahoo,项目名称:anthelion,代码行数:61,代码来源:OutlinkExtractor.java

示例13: execute

import org.apache.oro.text.regex.PatternMatcher; //导入方法依赖的package包/类
public cfData execute(cfSession _session, cfArgStructData argStruct ) throws cfmRunTimeException {
	String regexp = getNamedStringParam(argStruct, "regular", "");
	String strToSearch = getNamedStringParam(argStruct, "string", "");
	boolean bUnique = getNamedBooleanParam(argStruct, "unique",false);
	
	HashSet<String>	uniqueTrack = null;
	if ( bUnique ){
		uniqueTrack	= new HashSet<String>();
	}


	/* Setup the RegEx */
	PatternCompiler compiler = new Perl5Compiler();
	Pattern pattern;
	
	try {
		if (caseSensitiveMatch) {
			pattern = compiler.compile(regexp, Perl5Compiler.SINGLELINE_MASK);
		} else {
			pattern = compiler.compile(regexp, Perl5Compiler.CASE_INSENSITIVE_MASK | Perl5Compiler.SINGLELINE_MASK);
		}
	} catch (MalformedPatternException e) {
		cfCatchData catchD = new cfCatchData();
		catchD.setType("Function");
		catchD.setMessage("REMatch - invalid parameter");
		catchD.setDetail("Invalid regular expression ( " + regexp + " )");
		throw new cfmRunTimeException(catchD);
	}

	/* Perform the search */
	cfArrayData	array	= cfArrayData.createArray(1);
	PatternMatcher matcher = new Perl5Matcher();
	MatchResult result;
	PatternMatcherInput input = new PatternMatcherInput( strToSearch );
	while ( matcher.contains(input, pattern) ) {
		result = matcher.getMatch();
		
		String strResult = result.toString();
		if ( bUnique ){
			if ( !uniqueTrack.contains( strResult ) ){
				array.addElement( new cfStringData( strResult ) );
				uniqueTrack.add( strResult );
			}
		}else		
			array.addElement( new cfStringData( strResult ) );
	}
	
	return array;
}
 
开发者ID:OpenBD,项目名称:openbd-core,代码行数:50,代码来源:reMatch.java


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