// 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)^>
(?P<header>
[^\n()]*
(?:\((?P<name>[^\n()]+)\))?
[^()\n]*
)
[\n\r]
(?P<content>[\s\S]+?)(?=^>|\Z)").unwrap();
let string = ">XM_024446048.1 PREDICTED: Homo sapiens mannosidase alpha class 2A member 1 (MAN2A1), transcript variant X2, mRNA
CAGCCCCC
TGAGCGAC
TCCCTAATGTG
ACAGTAAAGAA
>NM_001308028.1 Homo sapiens FER tyrosine kinase (FER), transcript variant 2, mRNA
CAGCCC
CCGTGACGC
GGGGTGGTGACT
GGCTC
GGTGGT
GTGAC
>NM_0013082323028.1 H STZ mRSN1A
CAGCCC
CCGTGACGC
GGG
GTGGTGA
CTGGCTCCGGAGT
CTGAGGGGTTCGG";
// 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/