[][src]Function fungus::sys::extract_string

pub fn extract_string<T: AsRef<Path>>(path: T, rx: &Regex) -> Result<String>

Returns the first captured string from the given regular expression rx.

Examples

use fungus::prelude::*;

let tmpdir = PathBuf::from("tests/temp").abs().unwrap().mash("file_doc_extract_string");
assert!(sys::remove_all(&tmpdir).is_ok());
let tmpfile = tmpdir.mash("file1");
assert!(sys::mkdir(&tmpdir).is_ok());
let rx = Regex::new(r"'([^']+)'\s+\((\d{4})\)").unwrap();
assert!(sys::write(&tmpfile, "Not my favorite movie: 'Citizen Kane' (1941).").is_ok());
assert_eq!(sys::extract_string(&tmpfile, &rx).unwrap(), "Citizen Kane");
assert!(sys::remove_all(&tmpdir).is_ok());