// 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)\\RequirePackage(\[([^][]*)\])?([^{]*){([^{}]*)}.*(?:\n\s*\[([^][]*)])?").unwrap();
let string = "\\RequirePackage[
top = 2.5cm,
bottom = 2.5cm,
left = 2.5cm,
right = 2.5cm,
marginparwidth = 2cm,
marginparsep = 2mm,
heightrounded
]{geometry}%
[2020-01-02]
\\RequirePackage{tocbasic}
\\RequirePackage[svgnames]%
{xcolor}%
[2023/11/15]
\\RequirePackage[raggedright]% OK?
{titlesec}
\\RequirePackage{xcolor}%
[2022/06/12]
\\RequirePackage{hyperref}% To load after titlesec!
[2023-02-07]";
// 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/