// 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"(?s)type\s([_A-Za-z]+)\s*=\s*(function|procedure)(.*?cdecl;)\s*var(\s[_A-Za-z]+):\s*([_A-Za-z]+)\s(external.*?;)").unwrap();
let string = "
// It's better to create the object with the right prototype from the start.
type TJS_SetPrototype = function (cx: PJSContext; var obj: PJSObject;
var proto: PJSObject):Boolean; cdecl;
var JS_SetPrototype: TJS_SetPrototype external SpiderMonkeyLib name 'SM_SetPrototype';
/// Write access an object's reserved slots
type TJS_SetReservedSlot = procedure (obj: PJSObject; index: uint32;
var v: jsval); cdecl;
var JS_SetReservedSlot: TJS_SetReservedSlot external SpiderMonkeyLib name 'SM_SetReservedSlot';
";
// 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/