Skip to content

Instantly share code, notes, and snippets.

@kstep
Created March 11, 2015 16:13
Show Gist options
  • Select an option

  • Save kstep/0858a5c2805f4a7400e3 to your computer and use it in GitHub Desktop.

Select an option

Save kstep/0858a5c2805f4a7400e3 to your computer and use it in GitHub Desktop.

Revisions

  1. kstep created this gist Mar 11, 2015.
    23 changes: 23 additions & 0 deletions main.rs
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,23 @@
    #![feature(plugin)]
    #![plugin(regex_macros)]

    extern crate regex;

    use std::ops::Index;
    use regex::Regex;

    pub struct Re(Regex);

    impl Index<Re> for str {
    type Output = str;
    fn index<'b>(&'b self, index: &Re) -> &'b str {
    let (from, to) = index.0.find(self).unwrap();
    &self[from..to]
    }
    }


    fn main() {
    let m = &"abbccc"[Re(regex!("ab+"))];
    println!("{:?}", m);
    }