// 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"(?m)(?P<origin>(?P<protocol>http[s]?:)?\/\/(?P<host>[a-z0-9A-Z-_.]+))(?P<port>:\d+)?(?P<path>[\/a-zA-Z0-9-\.]+)?(?P<search>\?[^#\n]+)?(?P<hash>#.*)?").unwrap();
let string = "https://www.geeksforgeeks.org/lru-cache-implementation/#hastest?name=234ksldjfkl&sjkldf=
https://developer.ibm.com/series/kubernetes-learning-path/
https://www.google.com/search?q=cannot+find+package+%22context%22+in+any+of%3A&oq=cannot+find+package+%22context%22+in+any+of%3A&aqs=chrome..69i57j0l5.205752j0j4&sourceid=chrome&ie=UTF-8#hello world
https://myaccount.google.com/name?utm_source=google-account&utm_medium=web&pli=1&rapt=AEjHL4PXc8zLqgFQOXxYQRbdKJI8\\nyNq3u&name=rjl@1239015423#Kkn1HwudmOHSj7MpYAguZoOmrznrl0PF7hyLkZ17xFdrXToG5UDkMhO2bM1a6i5xw#path=234&sp=\\n";
// 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/