// 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"(?x)(?<obj>[a-zA-Z_$][\w.\n]+\.)?(?<func>[a-zA-Z_$][^. ]+)\s*(?<args>\((?:(?:[^()]+)|(?3))*\))").unwrap();
let string = "var someVar = myValue; object.subob
ject.function(with, some = obj.func(a, b[2][1]), arguments); return true;
// or
var someVar = myValue; object.subobject.function(with, some = obj.fu
nc(a, b[2][1]), arguments); return true;
// or
var someVar = myValue; object.subobject.funct
ion(with, some = obj.func(a, b[2][1]), arguments); retun true;
// and so on";
// 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/