File: simple.rs

package info (click to toggle)
rust-onig 6.5.1-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 300 kB
  • sloc: makefile: 4
file content (21 lines) | stat: -rw-r--r-- 551 bytes parent folder | download | duplicates (16)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
use onig::*;

fn main() {
    let pattern = "a(.*)b|[e-f]+";
    let string = "zzzzaffffffffb";

    let r = Regex::new(pattern).unwrap();

    match r.captures(string) {
        Some(caps) => {
            println!("match at {}", caps.offset());
            for (i, cap) in caps.iter_pos().enumerate() {
                match cap {
                    Some(pos) => println!("{}: {:?}", i, pos),
                    None => println!("{}: did not capture", i),
                }
            }
        }
        None => println!("search fail"),
    }
}