1 extern crate onig;
2
3 use onig::*;
4
main()5 fn main() {
6 let pattern = "(?<foo>a*)(?<bar>b*)(?<foo>c*)";
7 let string = "aaabbbbcc";
8
9 let r = Regex::new(pattern).unwrap();
10
11 println!("has {} group names:", r.capture_names_len());
12
13 r.foreach_name(|name, indices| {
14 println!("- {}: {:?}", name, indices);
15 true
16 });
17
18 let mut region = Region::new();
19
20 if let Some(position) = r.search_with_options(
21 string,
22 0,
23 string.len(),
24 SearchOptions::SEARCH_OPTION_NONE,
25 Some(&mut region),
26 ) {
27 println!("match at {} in {:?}", position, string);
28
29 r.foreach_name(|name, groups| {
30 for group in groups {
31 let pos = region.pos(*group as usize).unwrap();
32 println!("- {} ({}): {} - {}", name, group, pos.0, pos.1);
33 }
34
35 true
36 });
37 } else {
38 println!("search fail")
39 }
40 }
41