// 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"(?sm)(CREATE TABLE.*?;)").unwrap();
let string = "DROP TABLE IF EXISTS `aes_interval`;
CREATE TABLE `aes_interval` (
`processcode` bigint(20) NOT NULL,
`overstaying` int(11) NOT NULL,
`floating` int(11) NOT NULL,
PRIMARY KEY (`processcode`) USING BTREE
) ENGINE = InnoDB CHARACTER SET = utf8 COLLATE = utf8_general_ci;
by running a RegEx that would select all in between (...) i will be able to get an output/substringed text like below:
CREATE TABLE `aes_interval` (
`processcode` bigint(20) NOT NULL,
`overstaying` int(11) NOT NULL,
`floating` int(11) NOT NULL,
PRIMARY KEY (`processcode`) USING BTREE
);";
// 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/