peach-workspace/peach-network/src/utils.rs

19 lines
497 B
Rust

use regex::Regex;
use crate::error::NetworkError;
/// Return matches for a given Regex pattern and text
///
/// # Arguments
///
/// * `pattern` - A string slice containing a regular expression
/// * `text` - A string slice containing the text to be matched on
///
pub fn regex_finder(pattern: &str, text: &str) -> Result<Option<String>, NetworkError> {
let re = Regex::new(pattern)?;
let caps = re.captures(text);
let result = caps.map(|caps| caps[1].to_string());
Ok(result)
}