// 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"(?i)(?:http(s)?://)?([a-z][-\w]+(?:\.\w+)+(?:\S+)?)").unwrap();
let string = "Here is a sentence with a url containing a query string: https://www.google.com/search?q=mickmackusa&oq=mickmackusa&aqs=chrome..69i57j69i60.271j0j7&sourceid=chrome&ie=UTF-8 all good.
http://google.com
http://google.com.au
https://google.com.au
www.google.com
google.com
I went to the local food store and bought some food.\\n\\nI was able to find everything
I went to the local food store and bought some food.
I was able to find everything";
let substitution = "<a href=\"http$1://$2\" target=\"_blank\" title=\"$0\">$0</a>";
// result will be a String with the substituted value
let result = regex.replace_all(string, substitution);
println!("{}", result);
}
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/