// 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)^\[.*\]\n+((?:;;.*\n+)+)").unwrap();
let string = "[TITLE]
[OPTIONS]
;;Options Value
;;------------------ ------------
FLOW_UNITS CFS
<MORE TEXT>
[PATTERNS]
;;Name Type Multipliers
;;-------------- ---------- -----------
;Daily pattern generated from time series '2-166:2-165 (obs)'. Average value was 0.0485 MGD.
2-166:2-165_(obs)_Daily DAILY 1.011 1.008 1.06 0.908 1.072 0.998 0.942
<MORE TEXT>
[COORDINATES]
;;Node X-Coord Y-Coord
;;-------------- ---------------- ----------------
<MORE TEXT>
[JUNCTIONS]
;; Invert Max. Init. Surcharge Ponded
;;Name Elev. Depth Depth Depth Area
;;-------------- ---------- ---------- ---------- ---------- ----------
1-1 837.85 15.25 0 0 0
<MORE TEXT>
[REPORT]
INPUT YES
CONTROLS NO
<MORE TEXT>";
// 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/