Skip to main content

extract_string

Function extract_string 

Source
pub fn extract_string<T>(path: T, rx: &Regex) -> Result<String, FuError>
where T: AsRef<Path>,
Expand description

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());