// 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)^(?!.*://)(?P<md>.*\.[mM][dD])?(?P<section>#.*)?$").unwrap();
let string = "We want to find relative markdown urls, we don't care about https or ftp:// type urls...
^(?:(?!(?:https?|ftp)://).*)(?P<md>\\.[mM][dD])(?P<section>#?.*)$
https://github.com/tomduck/pandoc-fignos
http://github.com/tomduck/pandoc-fignos
ftp://github.com/tomduck/pandoc-fignos
ftp://github.com/ tomduck/ pandoc-fignos
ftp:// github.com/ tomduck/ pandoc-fignos
ftps://github.com/tomduck/pandoc-fignos
www.google.ca
google.com
./ch0_1_images.md#fig:ch0_1_images-1
./ch0_1_images.md#fig:ch0_1_images-2
./ch0_2_equations.md#sec:ch0_2_equations-1
./ch0_2_equations.md#eq:ch0_2_equations-1
./ch0_2_equations.md#eq:ch0_2_equations-2
./ch0_2_equations.md
./hello world.md
#eq:ch0_2_equations-2
#eq:ch0_2_equations-2";
// 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/