// 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"(?si)(?<=where)(.*?)((ORDER BY|GROUP BY|HAVING|LIMIT|OFFSET|$).*)").unwrap();
let string = "select \"DIM_1\".\"col1\",
\"DIM_2\".\"col2\" ,
\"DIM_3\".\"col3\" ,
\"DIM_4\".\"col4\" ,
\"FAT_1\".\"col5\"
from \"FAT_1\",
\"DIM_1\",
\"DIM_2\",
\"DIM_3\",
\"DIM_4\"
where \"DIM_1\".\"col1\" IS NOT NULL
AND \"DIM_2\".\"col2\" LIKE ('SUCCESS')
AND \"DIM_3\".\"col3\" BETWEEN 20161213 AND 20161222
AND \"DIM_4\".\"col4\" > 0
HAVING DIM_1.col1 > 2";
// 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/