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


Java Matcher类代码示例

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


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

示例1: toRegex

import org.joni.Matcher; //导入依赖的package包/类
/**
 * converts a grok expression into a named regex expression
 *
 * @return named regex expression
 */
public String toRegex(String grokPattern) {
    byte[] grokPatternBytes = grokPattern.getBytes(StandardCharsets.UTF_8);
    Matcher matcher = GROK_PATTERN_REGEX.matcher(grokPatternBytes);

    int result = matcher.search(0, grokPatternBytes.length, Option.NONE);
    if (result != -1) {
        Region region = matcher.getEagerRegion();
        String namedPatternRef = groupMatch(NAME_GROUP, region, grokPattern);
        String subName = groupMatch(SUBNAME_GROUP, region, grokPattern);
        // TODO(tal): Support definitions
        String definition = groupMatch(DEFINITION_GROUP, region, grokPattern);
        String patternName = groupMatch(PATTERN_GROUP, region, grokPattern);
        String pattern = patternBank.get(patternName);

        String grokPart;
        if (namedCaptures && subName != null) {
            grokPart = String.format(Locale.US, "(?<%s>%s)", namedPatternRef, pattern);
        } else if (!namedCaptures) {
            grokPart = String.format(Locale.US, "(?<%s>%s)", patternName + "_" + String.valueOf(result), pattern);
        } else {
            grokPart = String.format(Locale.US, "(?:%s)", pattern);
        }

        String start = new String(grokPatternBytes, 0, result, StandardCharsets.UTF_8);
        String rest = new String(grokPatternBytes, region.end[0], grokPatternBytes.length - region.end[0], StandardCharsets.UTF_8);
        return start + toRegex(grokPart + rest);
    }

    return grokPattern;
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:36,代码来源:Grok.java

示例2: captures

import org.joni.Matcher; //导入依赖的package包/类
/**
 * Matches and returns any named captures within a compiled grok expression that matched
 * within the provided text.
 *
 * @param text the text to match and extract values from.
 * @return a map containing field names and their respective coerced values that matched.
 */
public Map<String, Object> captures(String text) {
    byte[] textAsBytes = text.getBytes(StandardCharsets.UTF_8);
    Map<String, Object> fields = new HashMap<>();
    Matcher matcher = compiledExpression.matcher(textAsBytes);
    int result = matcher.search(0, textAsBytes.length, Option.DEFAULT);
    if (result != -1 && compiledExpression.numberOfNames() > 0) {
        Region region = matcher.getEagerRegion();
        for (Iterator<NameEntry> entry = compiledExpression.namedBackrefIterator(); entry.hasNext();) {
            NameEntry e = entry.next();
            String groupName = new String(e.name, e.nameP, e.nameEnd - e.nameP, StandardCharsets.UTF_8);
            for (int number : e.getBackRefs()) {
                if (region.beg[number] >= 0) {
                    String matchValue = new String(textAsBytes, region.beg[number], region.end[number] - region.beg[number],
                        StandardCharsets.UTF_8);
                    GrokMatchGroup match = new GrokMatchGroup(groupName, matchValue);
                    fields.put(match.getName(), match.getValue());
                    break;
                }
            }

        }
        return fields;
    } else if (result != -1) {
        return fields;
    }
    return null;
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:35,代码来源:Grok.java

示例3: compareTo

import org.joni.Matcher; //导入依赖的package包/类
@Override
public int compareTo(byte[] value, int offset, int length) {
  // Use subsequence match instead of full sequence match to adhere to the
  // principle of least surprise.
  Matcher m = pattern.matcher(value);
  return m.search(offset, length, pattern.getOptions()) < 0 ? 1 : 0;
}
 
开发者ID:fengchen8086,项目名称:ditb,代码行数:8,代码来源:RegexStringComparator.java

示例4: Search

import org.joni.Matcher; //导入依赖的package包/类
private OnigResult Search(byte[] data, int position, int end) {
	Matcher matcher = regex.matcher(data);
	int status = matcher.search(position, end, Option.DEFAULT);
	if (status != Matcher.FAILED) {
		Region region = matcher.getEagerRegion();
		return new OnigResult(region, -1);
	}
	return null;
}
 
开发者ID:eclipse,项目名称:tm4e,代码行数:10,代码来源:OnigRegExp.java

示例5: eval

import org.joni.Matcher; //导入依赖的package包/类
public boolean eval(PageReader pageReader)
{
    byte[] l = left.getString(pageReader).getBytes(StandardCharsets.UTF_8);
    Matcher matcher = regex.matcher(l);
    int result = matcher.search(0, l.length, Option.DEFAULT);
    return result != -1;
}
 
开发者ID:sonots,项目名称:embulk-filter-row,代码行数:8,代码来源:ParserExp.java

示例6: convertPatternOneLevel

import org.joni.Matcher; //导入依赖的package包/类
private String convertPatternOneLevel(String p) {
    String pattern = "\\%\\{[_0-9a-zA-Z]+(:[-_.0-9a-zA-Z]+){0,2}\\}";
    java.util.regex.Matcher m = java.util.regex.Pattern.compile(pattern)
            .matcher(p);
    String newPattern = "";
    int last_end = 0;
    while (m.find()) {
        newPattern += p.substring(last_end, m.start());
        String syntaxANDsemantic = m.group(0).substring(2,
                m.group(0).length() - 1);
        String syntax, semantic;
        String[] syntaxANDsemanticArray = syntaxANDsemantic.split(":", 3);

        syntax = syntaxANDsemanticArray[0];

        if (syntaxANDsemanticArray.length > 1) {
            semantic = syntaxANDsemanticArray[1];
            newPattern += "(?<" + semantic + ">" + patterns.get(syntax)
                    + ")";
        } else {
            newPattern += patterns.get(syntax);
        }
        last_end = m.end();
    }
    newPattern += p.substring(last_end);
    return newPattern;
}
 
开发者ID:childe,项目名称:hangout,代码行数:28,代码来源:Grok.java

示例7: MatcherStateImpl

import org.joni.Matcher; //导入依赖的package包/类
MatcherStateImpl(EncodedString encString, Matcher matcher, BitSet negativeLAGroups,
        Map<String, Integer> namedGroups) {
    this.encString = encString;
    this.matcher = matcher;
    this.negativeLAGroups = negativeLAGroups;
    this.namedGroups = namedGroups;
    this.byteLength = encString.byteLength();
    this.position = new StringPosition(encString, 0, 0, 0, 0);
}
 
开发者ID:anba,项目名称:es6draft,代码行数:10,代码来源:JoniRegExpMatcher.java

示例8: update

import org.joni.Matcher; //导入依赖的package包/类
private boolean update(int r) {
    begin = matcher.getBegin();
    end = matcher.getEnd();
    region = matcher.getRegion();
    position = position.relativeTo(begin, end);
    return r > Matcher.FAILED;
}
 
开发者ID:anba,项目名称:es6draft,代码行数:8,代码来源:JoniRegExpMatcher.java

示例9: match

import org.joni.Matcher; //导入依赖的package包/类
@Override
protected boolean match(Regex pattern, String searched) {
    byte[] str = getBytesUTF16LE(searched);
    Matcher matcher = pattern.matcher(str);
    return matcher.search(0, str.length, Option.DEFAULT) != -1;
}
 
开发者ID:fbacchella,项目名称:RegexPerf,代码行数:7,代码来源:State_org_joni_utf16le.java

示例10: match

import org.joni.Matcher; //导入依赖的package包/类
@Override
protected boolean match(Regex pattern, String searched) {
    byte[] str = getBytesAscii(searched);
    Matcher matcher = pattern.matcher(str);
    return matcher.search(0, str.length, Option.DEFAULT) != -1;
}
 
开发者ID:fbacchella,项目名称:RegexPerf,代码行数:7,代码来源:State_org_joni_ascii_reuse.java

示例11: match

import org.joni.Matcher; //导入依赖的package包/类
@Override
protected boolean match(Regex pattern, String searched) {
    byte[] str = searched.getBytes();
    Matcher matcher = pattern.matcher(str);
    return matcher.search(0, str.length, Option.DEFAULT) != -1;
}
 
开发者ID:fbacchella,项目名称:RegexPerf,代码行数:7,代码来源:State_org_joni.java

示例12: match

import org.joni.Matcher; //导入依赖的package包/类
/**
 * Checks whether a specific text matches the defined grok expression.
 *
 * @param text the string to match
 * @return true if grok expression matches text, false otherwise.
 */
public boolean match(String text) {
    Matcher matcher = compiledExpression.matcher(text.getBytes(StandardCharsets.UTF_8));
    int result = matcher.search(0, text.length(), Option.DEFAULT);
    return (result != -1);
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:12,代码来源:Grok.java


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