Advertisement
Guest User

Untitled

a guest
Feb 21st, 2017
103
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Rust 0.55 KB | None | 0 0
  1. fn env(expression: &str) -> Option<String> {
  2.     if let Ok(f) = File::open("/var/www/config/global/.env") {
  3.         let file = BufReader::new(f);
  4.  
  5.         let regex = Regex::new(expression).unwrap();
  6.  
  7.         let mut result: Option<String> = None;
  8.  
  9.         for line in file.lines() {
  10.             let l = line.unwrap();
  11.  
  12.             if regex.is_match(&l) {
  13.                 for cap in regex.captures_iter(&l) {
  14.                     result = Some(cap[1].to_string());
  15.                 }
  16.             }
  17.         }
  18.  
  19.         result
  20.     }
  21.  
  22.     None
  23. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement