// include the latest version of the regex crate in your Cargo.toml
extern crate regex;
use regex::Regex;
fn main() {
let regex = Regex::new(r"car (zap(?: zap| yes| xerox| with| view| under| this| sort| rest| quick| pie| orange| nope| meal| letter| kayak| joseph| indiana| humus| gelatin| frankfurter| elephant| doormat| carrot| banana| apple)?|yes(?: zap| yes| xerox| with| view| under| this| sort| rest| quick| pie| orange| nope| meal| letter| kayak| joseph| indiana| humus| gelatin| frankfurter| elephant| doormat| carrot| banana| apple)?|xerox(?: zap| yes| xerox| with| view| under| this| sort| rest| quick| pie| orange| nope| meal| letter| kayak| joseph| indiana| humus| gelatin| frankfurter| elephant| doormat| carrot| banana| apple)?|with(?: zap| yes| xerox| with| view| under| this| sort| rest| quick| pie| orange| nope| meal| letter| kayak| joseph| indiana| humus| gelatin| frankfurter| elephant| doormat| carrot| banana| apple)?|view(?: zap| yes| xerox| with| view| under| this| sort| rest| quick| pie| orange| nope| meal| letter| kayak| joseph| indiana| humus| gelatin| frankfurter| elephant| doormat| carrot| banana| apple)?|under(?: zap| yes| xerox| with| view| under| this| sort| rest| quick| pie| orange| nope| meal| letter| kayak| joseph| indiana| humus| gelatin| frankfurter| elephant| doormat| carrot| banana| apple)?|this(?: zap| yes| xerox| with| view| under| this| sort| rest| quick| pie| orange| nope| meal| letter| kayak| joseph| indiana| humus| gelatin| frankfurter| elephant| doormat| carrot| banana| apple)?|sort(?: zap| yes| xerox| with| view| under| this| sort| rest| quick| pie| orange| nope| meal| letter| kayak| joseph| indiana| humus| gelatin| frankfurter| elephant| doormat| carrot| banana| apple)?|rest(?: zap| yes| xerox| with| view| under| this| sort| rest| quick| pie| orange| nope| meal| letter| kayak| joseph| indiana| humus| gelatin| frankfurter| elephant| doormat| carrot| banana| apple)?|quick|(?: zap| yes| xerox| with| view| under| this| sort| rest| quick| pie| orange| nope| meal| letter| kayak| joseph| indiana| humus| gelatin| frankfurter| elephant| doormat| carrot| banana| apple)?|orange(?: zap| yes| xerox| with| view| under| this| sort| rest| quick| pie| orange| nope| meal| letter| kayak| joseph| indiana| humus| gelatin| frankfurter| elephant| doormat| carrot| banana| apple)?|nope|(?: zap| yes| xerox| with| view| under| this| sort| rest| quick| pie| orange| nope| meal| letter| kayak| joseph| indiana| humus| gelatin| frankfurter| elephant| doormat| carrot| banana| apple)?|letter(?: zap| yes| xerox| with| view| under| this| sort| rest| quick| pie| orange| nope| meal| letter| kayak| joseph| indiana| humus| gelatin| frankfurter| elephant| doormat| carrot| banana| apple)?|kayak(?: zap| yes| xerox| with| view| under| this| sort| rest| quick| pie| orange| nope| meal| letter| kayak| joseph| indiana| humus| gelatin| frankfurter| elephant| doormat| carrot| banana| apple)?|joseph(?: zap| yes| xerox| with| view| under| this| sort| rest| quick| pie| orange| nope| meal| letter| kayak| joseph| indiana| humus| gelatin| frankfurter| elephant| doormat| carrot| banana| apple)?|indiana(?: zap| yes| xerox| with| view| under| this| sort| rest| quick| pie| orange| nope| meal| letter| kayak| joseph| indiana| humus| gelatin| frankfurter| elephant| doormat| carrot| banana| apple)?|humus(?: zap| yes| xerox| with| view| under| this| sort| rest| quick| pie| orange| nope| meal| letter| kayak| joseph| indiana| humus| gelatin| frankfurter| elephant| doormat| carrot| banana| apple)?|gelatin(?: zap| yes| xerox| with| view| under| this| sort| rest| quick| pie| orange| nope| meal| letter| kayak| joseph| indiana| humus| gelatin| frankfurter| elephant| doormat| carrot| banana| apple)?|frankfurter(?: zap| yes| xerox| with| view| under| this| sort| rest| quick| pie| orange| nope| meal| letter| kayak| joseph| indiana| humus| gelatin| frankfurter| elephant| doormat| carrot| banana| apple)?|elephant(?: zap| yes| xerox| with| view| under| this| sort| rest| quick| pie| orange| nope| meal| letter| kayak| joseph| indiana| humus| gelatin| frankfurter| elephant| doormat| carrot| banana| apple)?|doormat(?: zap| yes| xerox| with| view| under| this| sort| rest| quick| pie| orange| nope| meal| letter| kayak| joseph| indiana| humus| gelatin| frankfurter| elephant| doormat| carrot| banana| apple)?|carrot(?: zap| yes| xerox| with| view| under| this| sort| rest| quick| pie| orange| nope| meal| letter| kayak| joseph| indiana| humus| gelatin| frankfurter| elephant| doormat| carrot| banana| apple)?|banana(?: zap| yes| xerox| with| view| under| this| sort| rest| quick| pie| orange| nope| meal| letter| kayak| joseph| indiana| humus| gelatin| frankfurter| elephant| doormat| carrot| banana| apple)?|apple(?: zap| yes| xerox| with| view| under| this| sort| rest| quick| pie| orange| nope| meal| letter| kayak| joseph| indiana| humus| gelatin| frankfurter| elephant| doormat| carrot| banana| apple)?) crashed").unwrap();
let string = "car apple view crashed
car doormat elephant crashed
car humus zap crashed
car banana crashed
car crashedddd
^ the above shouldn't matchd";
// result will be an iterator over tuples containing the start and end indices for each match in the string
let result = regex.captures_iter(string);
for mat in result {
println!("{:?}", mat);
}
}
Please keep in mind that these code samples are automatically generated and are not guaranteed to work. If you find any syntax errors, feel free to submit a bug report. For a full regex reference for Rust, please visit: https://docs.rs/regex/latest/regex/