// 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"coords.*\{[^}]+:.(\d+),[^}]+:.(\d*)\n.*}").unwrap();
let string = "{
\"name\": \"Medicare Annual Wellness Visit\",
\"translate\": false,
\"in_battery\": false,
\"action\": \"submitTest.php\",
\"conditionals_file\": \"conditionals-mwc.js\",
\"alias\": \"MWC\",
\"pdf_template\": \"annual_wellness_questionnaire.pdf\",
\"info\": \"Please complete this checklist before seeing your doctor or nurse\",
\"questions\": [
{
\"title_eng\": \"What is your age?\",
\"title_esp\": \"\",
\"scoring_method\": \"\",
\"range_type\": \"age\",
\"is_last\": false,
\"coords\": {
\"y\": 112,
\"x\": 38
}
},
{
\"title_eng\": \"Are you male or a female?\",
\"title_esp\": \"\",
\"scoring_method\": \"\",
\"range_type\": \"gender\",
\"is_last\": false,
\"coords\": {
\"y\": 121,
\"x\": 38
}
},
{
\"title_eng\": \"During the past four weeks, has your physical and emotional health limited your social activities with family, friends and groups?\",
\"title_esp\": \"\",
\"scoring_method\": \"\",
\"range_type\": \"state_slight\",
\"is_last\": false,
\"coords\": {
\"y\": 140,
\"x\": 38
}
},
{
\"title_eng\": \"During the past four weeks, how much body pain have you generally had?\",
\"title_esp\": \"\",
\"scoring_method\": \"\",
\"range_type\": \"state_pain\",
\"is_last\": false,
\"coords\": {
\"y\": 154,
\"x\": 38
}
},
{
\"title_eng\": \"During the past four weeks, was someone available to help you if you wanted or needed help?<br/>(For example, if you felt very nervous, lonely or blue; got sick and had to stay in bed; needed someone to talk to; needed help with daily chores; or needed help just taking care of yourself.)\",
\"title_esp\": \"\",
\"scoring_method\": \"\",
\"range_type\": \"affirm_qty\",
\"is_last\": false,
\"coords\": {
\"y\": 174,
\"x\": 38
}
},
{
\"title_eng\": \"During the past four weeks, what was the hardest physical activity you could do for at least 2 minutes?\",
\"title_esp\": \"\",
\"scoring_method\": \"\",
\"range_type\": \"state_grade\",
\"is_last\": false,
\"coords\": {
\"y\": 194,
\"x\": 38
}
},
{
\"title_eng\": \"Can you handle your own money without help?\",
\"title_esp\": \"\",
\"scoring_method\": \"\",
\"range_type\": \"boolean\",
\"is_last\": false,
\"coords\": {
\"y\": 206,
\"x\": 38
}
},
{
\"title_eng\": \"During the past four weeks, how would you rate your health in general?\",
\"title_esp\": \"\",
\"scoring_method\": \"\",
\"range_type\": \"state_rate\",
\"is_last\": false,
\"coords\": {
\"y\": 222.5,
\"x\": 39
}
},
{
\"title_eng\": \"How have things been going for you in the past four weeks?\",
\"title_esp\": \"\",
\"scoring_method\": \"\",
\"range_type\": \"life\",
\"is_last\": false,
\"coords\": {
\"y\": 238,
\"x\": 39
}
},
{
\"title_eng\": \"Are you having difficulties driving your car?\",
\"title_esp\": \"\",
\"scoring_method\": \"\",
\"range_type\": \"boolean_drive\",
\"is_last\": false,
\"coords\": {
\"y\": 248,
\"x\": 39
}
},
{
\"title_eng\": \"Do you always fasten your seat belt when you are in the car?\",
\"title_esp\": \"\",
\"scoring_method\": \"\",
\"range_type\": \"boolean_drive_b\",
\"is_last\": false,
\"coords\": {
\"y\": 52,
\"x\": 136
}
},
{
\"title_eng\": \"How often during the past four weeks have you been bothered by falling or dizziness when standing?\",
\"title_esp\": \"\",
\"scoring_method\": \"linear_gradation\",
\"range_type\": \"state_freq\",
\"is_last\": false,
\"coords\": {
\"y\": 87,
\"x\": 173
}
},
{
\"title_eng\": \"How often during the past four weeks have you been bothered by sexual problems?\",
\"title_esp\": \"\",
\"scoring_method\": \"linear_gradation\",
\"range_type\": \"state_freq\",
\"is_last\": false,
\"coords\": {
\"y\": 94,
\"x\": 173
}
},
{
\"title_eng\": \"How often during the past four weeks have you had trouble eating well?\",
\"title_esp\": \"\",
\"scoring_method\": \"linear_gradation\",
\"range_type\": \"state_freq\",
\"is_last\": false,
\"coords\": {
\"y\": 100,
\"x\": 173
}
},
{
\"title_eng\": \"How often during the past four weeks have you been bothered by teeth or denture problems?\",
\"title_esp\": \"\",
\"scoring_method\": \"linear_gradation\",
\"range_type\": \"state_freq\",
\"is_last\": false,
\"coords\": {
\"y\": 105,
\"x\": 173
}
},
{
\"title_eng\": \"How often during the past four weeks have you been bothered by problems using the telephone?\",
\"title_esp\": \"\",
\"scoring_method\": \"linear_gradation\",
\"range_type\": \"state_freq\",
\"is_last\": false,
\"coords\": {
\"y\": 112,
\"x\": 173
}
},
{
\"title_eng\": \"How often during the past four weeks have you been bothered by tiredness or fatigue?\",
\"title_esp\": \"\",
\"scoring_method\": \"linear_gradation\",
\"range_type\": \"state_freq\",
\"is_last\": false,
\"coords\": {
\"y\": 117,
\"x\": 173
}
},
{
\"title_eng\": \"Have you fallen 2 or more times during the past year?\",
\"title_esp\": \"\",
\"scoring_method\": \"\",
\"range_type\": \"boolean\",
\"is_last\": false,
\"coords\": {
\"y\": 136,
\"x\": 137
}
},
{
\"title_eng\": \"Are you afraid of falling?\",
\"title_esp\": \"\",
\"scoring_method\": \"\",
\"range_type\": \"boolean\",
\"is_last\": false,
\"coords\": {
\"y\": 147,
\"x\": 137
}
},
{
\"title_eng\": \"Are you a smoker?\",
\"title_esp\": \"\",
\"scoring_method\": \"\",
\"range_type\": \"boolean_smoker\",
\"is_last\": false,
\"coords\": {
\"y\": 157,
\"x\": 137
}
},
{
\"title_eng\": \"During the past four weeks, how many drinks of wine, beer or other alcoholic beverages did you have?\",
\"title_esp\": \"\",
\"scoring_method\": \"\",
\"range_type\": \"freq_drinks\",
\"is_last\": false,
\"coords\": {
\"y\": 176,
\"x\": 137
}
},
{
\"title_eng\": \"Do you excercise for about 20 minutes three or more times a week?\",
\"title_esp\": \"\",
\"scoring_method\": \"\",
\"range_type\": \"freq_exer\",
\"is_last\": false,
\"coords\": {
\"y\": 190,
\"x\": 137
}
},
{
\"title_eng\": \"Have you been given any information to help you with hazards in your home that may hurt you?\",
\"title_esp\": \"\",
\"scoring_method\": \"\",
\"range_type\": \"boolean\",
\"is_last\": false,
\"coords\": {
\"y\": 204,
\"x\": 187
}
},
{
\"title_eng\": \"Have you been given any information to help you with keeping track of your medications?\",
\"title_esp\": \"\",
\"scoring_method\": \"\",
\"range_type\": \"boolean\",
\"is_last\": false,
\"coords\": {
\"y\": 209,
\"x\": 187
}
},
{
\"title_eng\": \"How often have you had trouble taking medications the way you are told to take them?\",
\"title_esp\": \"\",
\"scoring_method\": \"\",
\"range_type\": \"freq_meds\",
\"is_last\": false,
\"coords\": {
\"y\": 224,
\"x\": 137
}
},
{
\"title_eng\": \"How confident are you that you can control and manage most of your health problems?\",
\"title_esp\": \"\",
\"scoring_method\": \"\",
\"range_type\": \"state_confidence\",
\"is_last\": false,
\"coords\": {
\"y\": 238,
\"x\": 137
}
},
{
\"title_eng\": \"What is your race? (Check all that apply)\",
\"title_esp\": \"\",
\"scoring_method\": \"race\",
\"range_type\": \"race\",
\"is_last\": true,
\"coords\": {
\"y\": 243,
\"x\": 137
}
}
]
}";
// 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/