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