// 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"(?mx)(?:(?<=^\n)|(?<=\A)) # Needs 1 or more new lines or start of string
(?<para_all>
(?<para_prefix>[ ]{0,3}) # Possibly some leading spaces, but less than a tab worth
(?<para_content>
(?:
(?! # some line content not starting with those exceptions
[[:blank:]\h]{0,3}
(?:
\*{1}[ \t]+ # a list
|
(?:\*(?:[ ]?\*){2,}) # a horizontal line
|
(?:\-*(?:[ ]?\-){2,}) # a horizontal line
|
(?:\_*(?:[ ]?\_){2,}) # a horizontal line
|
[>+-=\#]
|
\d+\. # ordered list
|
\`{3,} # code block
|
\~{3,} # code block extended
)
)
)
.+
(?!\n(?:[=-]+))
(?:\n|$)
)+
)").unwrap();
let string = "***This is strong and em.***
The quick brown fox
jumps over the lazy dog
Lorem Ipsum
I should match
- I should NOT match
Le sigh
> Why am I matching?
1. Nonononono!
* Aaaagh!
# Stahhhp!
Hello, World!
==
---
***
***
***
***
***
* * *
* * *
* * *
* * *
___
___
___
___
";
// 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/