File: simple.rs

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

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"),
    }
}