-
-
Save subhojit777/a5c73a44701a3d48782f9b74529e82e1 to your computer and use it in GitHub Desktop.
Code shared from the Rust Playground
This file contains hidden or 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