Skip to content

Instantly share code, notes, and snippets.

@rust-play
Created July 18, 2018 05:48
Show Gist options
  • Save rust-play/54c6bbfce4e3fd40d02c7a236487696b to your computer and use it in GitHub Desktop.
Save rust-play/54c6bbfce4e3fd40d02c7a236487696b to your computer and use it in GitHub Desktop.
Code shared from the Rust Playground
extern crate regex;
use regex::RegexBuilder;
use std::fmt::Write;
fn main() {
let query = "is";
let mut query_as_string = String::from("");
if true {
write!(query_as_string, r"\b{}\b", query).unwrap();
} else {
write!(query_as_string, r"{}", query).unwrap();
}
let mut regex_builder = RegexBuilder::new(&query_as_string);
regex_builder.case_insensitive(true);
let regex = regex_builder.build().unwrap();
let text = "Retroactively relinquishing remunerations is reprehensible.";
for mat in regex.find_iter(text) {
println!("{:#?}", mat.start());
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment