Skip to content

Instantly share code, notes, and snippets.

@kstep kstep/main.rs
Created Mar 11, 2015

Embed
What would you like to do?
#![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);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.