// 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)^jdbc:oracle:thin:((?P<username>[a-zA-Z0-9]{1,})([\/](?P<password>[a-zA-Z0-9]{1,})){0,1}){0,1}@(?P<ezdb_name>((\/\/){0,1}(?P<hostname>[a-zA-Z0-9\.\-]{1,})(\:(?P<port>\d+)){0,1})(\/(?P<service_name>[a-zA-Z\.\-0-9]{1,}(\:(?P<server_type>[a-zA-Z]{1,})){0,1}){0,1}(\/(?P<instance_name>[a-zA-Z0-9]{1,})){0,1}){0,1})$").unwrap();
let string = "jdbc:oracle:thin:@//hostname.example.ru:1521/database.example.ru
jdbc:oracle:thin:@sales-server
jdbc:oracle:thin:@sales-server:3456
jdbc:oracle:thin:@sales-server/sales
jdbc:oracle:thin:@sales-server:80/sales
jdbc:oracle:thin:@sales-server/sales:dedicated/inst1
jdbc:oracle:thin:@sales-server//inst1
jdbc:oracle:thin:@sales-server:1521/sales.us.acme.com
jdbc:oracle:thin:@//sales-server/sales.us.acme.com
jdbc:oracle:thin:@//sales-server.us.acme.com/sales.us.oracle.com
jdbc:oracle:thin:wat@//sales-server.us.acme.com/sales.us.oracle.com
jdbc:oracle:thin:wat/wat@//sales-server.us.acme.com/sales.us.oracle.com
jdbc:oracle:thin:wat/wat@//sales-server.us.acme.com/sales.us.oracle.com:dedicated/instance
jdbc:oracle:thin:wat/wat@//sales-server.us.acme.com//instance
jdbc:oracle:thin:@hostname:1521:DATABASE
";
// 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/