Crates.io | grok-rs |
lib.rs | grok-rs |
version | 0.1.3 |
source | src |
created_at | 2024-06-07 12:39:58.760399 |
updated_at | 2024-06-09 06:55:33.408453 |
description | Rust port of elastic Grok processor |
homepage | |
repository | https://github.com/yuanbohan/grok-rs |
max_upload_size | |
id | 1264747 |
size | 121,456 |
the grok_rs
is a rust port of Elastic Grok processor, inspired by grok-go and grok
[dependencies]
grok-rs = "0.1.3"
let grok = Grok::default();
let pattern = grok
// USERNAME are defined in grok-patterns
.compile("%{USERNAME}", false)
.unwrap();
let result = pattern.parse("admin admin@example.com").unwrap();
println!("{:#?}", result);
the output is:
{
"USERNAME": String(
"admin",
),
}
let mut grok = Grok::default();
grok.add_pattern("NAME", r"[A-z0-9._-]+");
let pattern = grok.compile("%{NAME}", false).unwrap();
let result = pattern.parse("admin").unwrap();
println!("{:#?}", result);
the output is:
{
"NAME": String(
"admin",
),
}
named_capture_only
is truelet grok = Grok::default();
let pattern = grok
.compile("%{USERNAME} %{EMAILADDRESS:email}", true)
.unwrap();
let result = pattern.parse("admin admin@example.com").unwrap();
println!("{:#?}", result);
the output is:
{
"email": String(
"admin@example.com",
),
}
let mut grok = Grok::default();
grok.add_pattern("NUMBER", r"\d+");
let pattern = grok.compile("%{NUMBER:digit:int}", false).unwrap();
let result = pattern.parse("hello 123").unwrap();
println!("{:#?}", result);
the output is:
{
"digit": Int(
123,
),
}
grok_rs
is based on regex crate, so lacks several features that are not known how to implement efficiently. This includes, but is not limited to, look-around and backreferences. In exchange, all regex searches in this crate have worst case O(m * n)
time complexity, where m
is proportional to the size of the regex and n
is proportional to the size of the string being searched.
This crate declares compatible with elastic grok patterns v8.14.0, which is tagged at 2024-06-05.