// 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"(?ms)(?ms)(^NAME.*?)^\s+^\d").unwrap();
let string = "SQL*Plus: Release 11.2.0.1.0 Production on Wed Jan 27 13:46:07 2016
Copyright (c) 1982, 2010, Oracle. All rights reserved.
Connected to:
Oracle Database 11g Enterprise Edition Release 11.2.0.3.0 - 64bit Production
With the Partitioning, Real Application Clusters, Automatic Storage Management, OLAP,
Data Mining and Real Application Testing options
NAME
--------------------------------------------------------------------------------
Agent-Job Follow Up Missed Group D
Agent-Job Follow Up Missed Group E
Audit Archive
Day BGO - 705 and 705NA - A (2)
Day BGO - ERR Quebec - A
Dispatch Lunch Break Agent (Pre-Agent) - Group D
Helper Job Agent (Amend, Prevent, Lead) Group A
Incomplete Tasks Display Status Cleanup - Group A
Jeopardy Agent (Late EnRoute, OnSite, Complete) Group A
Jeopardy Agent (Late EnRoute, OnSite, Complete) Group B
Lunch Break Report Agent(Post-Agent) - Group A
NAME
--------------------------------------------------------------------------------
MST Validation - Group A
MST Validation - Group C
Unschedule INHS Tasks
Unschedule Jobs with Schedule Update Failure - Group E
15 rows selected.
Disconnected from Oracle Database 11g Enterprise Edition Release 11.2.0.3.0 - 64bit Production
With the Partitioning, Real Application Clusters, Automatic Storage Management, OLAP,
Data Mining and Real Application Testing options";
// result will be a tuple containing the start and end indices for the first match in the string
let result = regex.captures(string);
let (start, end) = match result {
Some((s, e)) => (s, e),
None => {
// ...
}
};
println!("{}", &string[start, end]);
}
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/