// 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#"(?i)(?:Subject:|Summary:)[^"]*"(.*?)""#).unwrap();
let string = "exports.onAppointment = (appt, user, lang, isNew) ->
if not user then return Promise.reject \"Appointment has no user.\"
moment.locale(lang)
start = moment(appt.when)
cal = new ICal()
console.log appt.when
cal.addEvent
start: start.toDate()
end: moment(start).add(2,\"hours\").toDate()
summary: \"Continental showroom visit\"
mail =
to: user.emailId
subject: if isNew then \"New appointment\" else \"Appointment updated\"
alternatives: [
contentType: \"text/calendar\",
contents: new Buffer(cal.toString()),
contentEncoding: \"7bit\"
]
template =
name: \"booking\"
lang: lang
locals:
name: \"#{user.firstName} #{user.lastName}\"
datetime: moment(appt.when).format(\"dddd Do MMMM [at] HH:mm A\")
cancelurl: config.server.baseUrl + \"/appointment/cancel/#{appt._id}\"
emailClient.send2 mail, template";
// 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/