本文整理了Java中io.krakens.grok.api.Grok.match()
方法的一些代码示例,展示了Grok.match()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Grok.match()
方法的具体详情如下:
包路径:io.krakens.grok.api.Grok
类名称:Grok
方法名:match
[英]Match the given text with the named regex Grok will extract data from the string and get an extence of Match.
[中]将给定文本与命名的regex-Grok匹配将从字符串中提取数据并获得匹配的扩展名。
代码示例来源:origin: Graylog2/graylog2-server
@Override
protected Result[] run(String value) {
// the extractor instance is rebuilt every second anyway
final Match match = grok.match(value);
final Map<String, Object> matches = match.capture();
final List<Result> results = new ArrayList<>(matches.size());
for (final Map.Entry<String, Object> entry : matches.entrySet()) {
// never add null values to the results, those don't make sense for us
if (entry.getValue() != null) {
results.add(new Result(entry.getValue(), entry.getKey(), -1, -1));
}
}
return results.toArray(new Result[0]);
}
}
代码示例来源:origin: apache/nifi
final Match match = grok.match(line);
valueMap = match.capture();
final StringBuilder trailingText = new StringBuilder();
while ((nextLine = reader.readLine()) != null) {
final Match nextLineMatch = grok.match(nextLine);
final Map<String, Object> nextValueMap = nextLineMatch.capture();
if (nextValueMap.isEmpty()) {
代码示例来源:origin: Graylog2/graylog2-server
@Override
public GrokResult evaluate(FunctionArgs args, EvaluationContext context) {
final String value = valueParam.required(args, context);
final String pattern = patternParam.required(args, context);
final boolean onlyNamedCaptures = namedOnly.optional(args, context).orElse(false);
if (value == null || pattern == null) {
return null;
}
final Grok grok = grokPatternRegistry.cachedGrokForPattern(pattern, onlyNamedCaptures);
final Match match = grok.match(value);;
return new GrokResult(match.capture());
}
代码示例来源:origin: Graylog2/graylog2-server
final Match match = grok.match(string);
final Map<String, Object> matches = match.capture();
代码示例来源:origin: apache/nifi
final Match gm = grok.match(contentString);
gm.setKeepEmptyCaptures(keepEmptyCaputures.get());
final Map<String,Object> captureMap = gm.capture();
代码示例来源:origin: thekrakken/java-grok
/**
* Match the given <tt>log</tt> with the named regex.
* And return the json representation of the matched element
*
* @param log : log to match
* @return map containing matches
*/
public Map<String, Object> capture(String log) {
Match match = match(log);
return match.capture();
}
代码示例来源:origin: thekrakken/java-grok
@Test
public void test009_ipOrPort() {
Grok grok = compiler.compile("%{IPORHOST}");
Match gm = grok.match("www.google.fr");
Map<String, Object> map = gm.capture();
assertEquals("{IPORHOST=www.google.fr}", map.toString());
gm = grok.match("www.google.com");
map = gm.capture();
assertEquals("{IPORHOST=www.google.com}", map.toString());
}
代码示例来源:origin: thekrakken/java-grok
@SuppressWarnings("unchecked")
@Test
public void test007_captureDuplicateName() throws GrokException {
Grok grok = compiler.compile("%{INT:id} %{INT:id}");
Match match = grok.match("123 456");
Map<String, Object> map = match.capture();
assertEquals(map.size(), 1);
assertEquals(((List<Object>) (map.get("id"))).size(), 2);
assertEquals(((List<Object>) (map.get("id"))).get(0), "123");
assertEquals(((List<Object>) (map.get("id"))).get(1), "456");
}
代码示例来源:origin: thekrakken/java-grok
@Test
public void test026_datetime_pattern_with_with_dots() throws Throwable {
final ZonedDateTime expectedDate = ZonedDateTime.of(2015, 7, 31, 0, 0, 0, 0, ZoneOffset.UTC);
final Grok grok = compiler.compile("Foo %{DATA:result;date;yyyy.MM.dd} Bar", ZoneOffset.UTC, false);
final Match gm = grok.match("Foo 2015.07.31 Bar");
assertEquals(1, gm.getMatch().groupCount());
assertEquals(expectedDate.toInstant(), gm.capture().get("result"));
}
代码示例来源:origin: thekrakken/java-grok
@Test
public void test025_datetime_pattern_with_slashes() throws Throwable {
final ZonedDateTime expectedDate = ZonedDateTime.of(2015, 7, 31, 0, 0, 0, 0, ZoneOffset.UTC);
final Grok grok = compiler.compile("Foo %{DATA:result;date;yyyy/MM/dd} Bar", ZoneOffset.UTC, false);
final Match gm = grok.match("Foo 2015/07/31 Bar");
assertEquals(1, gm.getMatch().groupCount());
assertEquals(expectedDate.toInstant(), gm.capture().get("result"));
}
代码示例来源:origin: thekrakken/java-grok
@Test
public void test027_datetime_pattern_with_with_hyphens() throws Throwable {
final ZonedDateTime expectedDate = ZonedDateTime.of(2015, 7, 31, 0, 0, 0, 0, ZoneOffset.UTC);
final Grok grok = compiler.compile("Foo %{DATA:result;date;yyyy-MM-dd} Bar", ZoneOffset.UTC, false);
final Match gm = grok.match("Foo 2015-07-31 Bar");
assertEquals(1, gm.getMatch().groupCount());
assertEquals(expectedDate.toInstant(), gm.capture().get("result"));
}
代码示例来源:origin: thekrakken/java-grok
@Test
public void test005_notSpace() {
Grok grok = compiler.compile("%{NOTSPACE}");
Match gm = grok.match("abc dc");
Map<String, Object> map = gm.capture();
assertEquals("{NOTSPACE=abc}", map.toString());
}
代码示例来源:origin: thekrakken/java-grok
@Test
public void test006_quotedString() {
Grok grok = compiler.compile("%{QUOTEDSTRING:text}");
Match gm = grok.match("\"abc dc\"");
Map<String, Object> map = gm.capture();
assertEquals("{text=abc dc}", map.toString());
}
代码示例来源:origin: thekrakken/java-grok
@Test
public void test010_hostPort() {
Grok grok = compiler.compile("%{HOSTPORT}");
Match gm = grok.match("www.google.fr:80");
Map<String, Object> map = gm.capture();
assertEquals(ImmutableMap.of(
"HOSTPORT", "www.google.fr:80",
"IPORHOST", "www.google.fr",
"PORT", "80"), map);
}
代码示例来源:origin: thekrakken/java-grok
@Test
public void test004_number() {
Grok grok = compiler.compile("%{NUMBER}");
Match gm = grok.match("Something costs $55.4!");
Map<String, Object> map = gm.capture();
assertEquals("{NUMBER=55.4}", map.toString());
}
代码示例来源:origin: thekrakken/java-grok
@Test
public void test004_space() {
Grok grok = compiler.compile("%{SPACE}");
Match gm = grok.match("abc dc");
Map<String, Object> map = gm.capture();
assertEquals("{SPACE=}", map.toString());
}
代码示例来源:origin: thekrakken/java-grok
@Test
public void test008_mac() {
Grok grok = compiler.compile("%{MAC}");
Match gm = grok.match("5E:FF:56:A2:AF:15");
Map<String, Object> map = gm.capture();
assertEquals("{MAC=5E:FF:56:A2:AF:15}", map.toString());
}
代码示例来源:origin: thekrakken/java-grok
@Test
public void test002_numbers() {
Grok grok = compiler.compile("%{NUMBER}");
Match gm = grok.match("-42");
Map<String, Object> map = gm.capture();
assertEquals("{NUMBER=-42}", map.toString());
}
代码示例来源:origin: thekrakken/java-grok
@Test
public void test006_captureOnlyNamed() throws GrokException {
compiler.register("abcdef", "[a-zA-Z]+");
compiler.register("ghijk", "\\d+");
Grok grok = compiler.compile("%{abcdef:abcdef}%{ghijk}", true);
Match match = grok.match("abcdef12345");
Map<String, Object> map = match.capture();
assertEquals(map.size(), 1);
assertNull(map.get("ghijk"));
assertEquals(map.get("abcdef"), "abcdef");
}
代码示例来源:origin: thekrakken/java-grok
@Test
public void test001_captureMathod() {
compiler.register("foo", ".*");
Grok grok = compiler.compile("%{foo}");
Match match = grok.match("Hello World");
assertEquals("(?<name0>.*)", grok.getNamedRegex());
assertEquals("Hello World", match.getSubject());
Map<String, Object> map = match.capture();
assertEquals(1, map.size());
assertEquals("Hello World", map.get("foo"));
assertEquals("{foo=Hello World}", map.toString());
}
内容来源于网络,如有侵权,请联系作者删除!