Crates.io | esre |
lib.rs | esre |
version | 0.1.1 |
source | src |
created_at | 2022-03-01 19:53:09.967672 |
updated_at | 2022-03-23 21:35:36.572681 |
description | alt regex library |
homepage | |
repository | https://gitlab.com/asvedr/esre |
max_upload_size | |
id | 541789 |
size | 85,992 |
// Make regex for '[a-z]+'
let word = Re::ranges('a'..='z').into_one_or_more();
// Make regex for url format
let re = Re::create("http")
.opt("s")
.join("://")
.join(word.clone())
.one_or_more(Re::create(".").join(word))
.opt("/")
.compile();
// Check matches
let opt_val = re.match_begin("https://x.com.ru");
let word = Re::ranges((('a' ..= 'z'), ('A' ..= 'Z'))).into_one_or_more().into_var("value");
let name = Re::create("name").opt(":").zero_or_more(" ").join(word.clone()).into_label("name");
let surname = Re::create("surname").opt(":").zero_or_more(" ").join(word.clone()).into_label("surname");
let re = Re::create("hi").one_or_more(" ").any_of((
name.clone().join(",").zero_or_more(" ").join(surname.clone()),
surname.join(",").zero_or_more(" ").join(name),
)).compile();
for source in &["123 hi name:Gordon, surname: Freeman", "hi surname:Freeman,name: Gordon"] {
let found = re.find(source).unwrap();
assert_eq!(found.get_var("name.value").unwrap(), "Gordon");
assert_eq!(found.get_var("surname.value").unwrap(), "Freeman");
}
let dump: serde_json::Value = Re::create(...).to_json();
let restored_re = Re::parse_json(&dump).unwrap().compile();
Re::create("abc")
Re::ranges(('a' ..= 'z'))
- [a-z]
Re::ranges((('a' ..= 'z'), '_'))
- [a-z_]
Re::ranges((('a' ..= 'z'), '_', ('0' ..= '9')))
- [a-z_0-9]
Re::opt("abc")
Re::any()
- .
Re::any().into_zero_or_more()
- .*
Re::zero_or_more("a")
- a*
Re::one_or_more("a")
- a+
Re::repeat(min, max, "a")
- repeat "a" max >= count >= min
Re::begin()
Re::end()
Re::not("x")
Re::stop_all_if("x")
Re::var("name", value)
Re::label("name", value)
Re::create("a").join(Re::any_of(("b", "c"))).join("d")
use same named methods instead of Re::*
Re::create("a").any_of(("b", "c")).opt("?")
join values into one superclass using methods 'into_*'
Re::ranges('a' ..= 'z').into_one_or_more().into_var("name")