// 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"(?m)(?:[^\n]*\n){4}([\s\S]*)").unwrap();
let string = "Однажды, в студёную зимнюю пору
Я из лесу вышел; был сильный мороз.
Гляжу, поднимается медленно в гору
Лошадка, везущая хворосту воз.
И, шествуя важно, в спокойствии чинном,
Лошадку ведёт под уздцы мужичок
В больших сапогах, в полушубке овчинном,
В больших рукавицах... а сам с ноготок!
«Здорово, парнище!» — «Ступай себе мимо!» —
«Уж больно ты грозен, как я погляжу!
Откуда дровишки?» — «Из лесу, вестимо,
Отец, слышишь, рубит, а я отвожу».
(В лесу раздавался топор дровосека.) —
«А что, у отца-то большая семья?» —
«Семья-то большая, да два человека
Всего мужиков-то: отец мой да я...» —";
// result will be a tuple containing the start and end indices for the first match in the string
let result = regex.captures(string);
let (start, end) = match result {
Some((s, e)) => (s, e),
None => {
// ...
}
};
println!("{}", &string[start, end]);
}
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/