Created
July 18, 2018 05:48
-
-
Save rust-play/54c6bbfce4e3fd40d02c7a236487696b to your computer and use it in GitHub Desktop.
Code shared from the Rust Playground
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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