// 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"\\([a-zA-Z]+ *|.|\n)").unwrap();
let string = "\\documentclass {book}
\\usepackage{a}
\\begin {document}
\\chapter*{This is the title of a index-absent chapter}
\\I'll try to do some actual \\LaTeX\\ text to se\\footnote {This is text in a footnote.} how it will be matched.
\\chapter{This is {\\bf another} chapter title}
You have to be carefull with accents, like ``Espa\\~nol''
and active characters (characters like the quotes above
or the newline character, which act by themselves as a
command).\\
You have to be carefull also with comments (beginning with
the percentage char) % this is one comment.
And of course you'll loose al your math, as in
$e^{i\\pi} + 1 = 0$.
\\end{document}
";
// 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/