1 extern crate onig;
2
3 use onig::*;
4
exec(syntax: &Syntax, pattern: &str, to_search: &str)5 fn exec(syntax: &Syntax, pattern: &str, to_search: &str) {
6 let reg = Regex::with_options(pattern, RegexOptions::REGEX_OPTION_NONE, syntax).unwrap();
7
8 match reg.captures(to_search) {
9 Some(caps) => {
10 println!("match at {}", caps.offset());
11 for (i, cap) in caps.iter_pos().enumerate() {
12 match cap {
13 Some(pos) => println!("{}: {:?}", i, pos),
14 None => println!("{}: did not capture", i),
15 }
16 }
17 }
18 None => println!("search fail"),
19 }
20 }
21
main()22 fn main() {
23 exec(
24 Syntax::perl(),
25 r"\p{XDigit}\P{XDigit}\p{^XDigit}\P{^XDigit}\p{XDigit}",
26 "bgh3a",
27 );
28
29 exec(Syntax::java(), r"\p{XDigit}\P{XDigit}[a-c&&b-g]", "bgc");
30
31 exec(
32 Syntax::asis(),
33 r"abc def* e+ g?ddd[a-rvvv] (vv){3,7}hv\dvv(?:aczui ss)\W\w$",
34 r"abc def* e+ g?ddd[a-rvvv] (vv){3,7}hv\dvv(?:aczui ss)\W\w$",
35 );
36 }
37