Function rustml::io::match_lines
[−]
[src]
pub fn match_lines<R: Read>(reader: R, r: Regex) -> MatchLines<R>
Returns an instance of MatchLines
which can be used to read all
lines from the given reader. Each line is matched against the provided regex
and only those lines which match the regex are returned.
Example
#[macro_use] extern crate rustml; extern crate regex; use std::fs::File; use std::io::BufReader; use regex::Regex; use rustml::io::match_lines; // the file lines.txt contains the lines: // line 1 // line 2 // line 3 let f = File::open("datasets/testing/lines.txt").unwrap(); let r = BufReader::new(f); let mut v = Vec::new(); for line in match_lines(r, Regex::new(r"^[a-z]+ (\d+)$").unwrap()) { let captures = line.unwrap(); v.push(captures[1].parse::<usize>().unwrap()); } assert_eq!(v, vec![1, 2, 3]);