// 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#"(?mix)\? # match the literal characters 'text'
(?= # start lookahead
[^"']* # match any number of non-quote characters
(?: # start non-capturing group, repeated zero or more times
("|')[^\1]*\1 # one quoted portion of text
[^"']* # any number of non-quote characters
)* # end non-capturing group
$ # match end of the string
) # end lookahead"#).unwrap();
let string = "test ? query
query ? test \"text ? text\" test ? id
query ? test 'text ? text' test ? eee
SELECT * FROM table1 WHERE id = ?
SELECT * FROM table1 WHERE (id IN (?)) AND (path = 'test?text')
SELECT * FROM table1 WHERE (id IN (?)) AND (path = \"test?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/