// 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"(?mi)(var.*=)\s+(([\{\[][\n\r]+[\S\s]*?[\r\n]+[\}\]]([\r\n]+|\Z))|([^\n\r]*))").unwrap();
let string = "var testmultiline = {
fizz = {
buzz = \"moo\"
}
buzz = {
buzz = \"moo\"
}
}
var test2 = null
var test3 = { still single line }
var randomportraits = load(globals.modfolder + \"/randomportraits/randomportraits.gd\").new()
<AddTo 0>
var races = {
HumanTest = {
skin = ['pale', 'fair', 'olive', 'tan'],
eyecolor = ['blue', 'green', 'brown', 'hazel', 'black', 'gray'],
haircolor = ['blond', 'red', 'auburn', 'brown', 'black'],
surname = names.humansurname,
description = \"Humans are a highly successful militaristic people whose members can be found throughout much of the world, their presence often receiving a mixed reception. Slavery is a common part of human society, viewed as a civilized form of alternative punishment, with many laws and businesses based around the concept. Because of this slave driven culture, you have found that humans tend to be the most widely accessible residents, servants, and slaves.\",
details = \"[color=aqua]Racial trait: Punishment expectations and praise lasts twice as long.[/color]\\n\\n[color=yellow]Stat potential: Strength - 5, Agility - 3, Magic - 2, Endurance - 4 [/color]\",
stats = {str_max = 5,
agi_max = 3,
maf_max = 2,
end_max = 4}
},
}";
// 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/