docs, errors and basic api
This commit is contained in:
18
src/utils.rs
Normal file
18
src/utils.rs
Normal file
@ -0,0 +1,18 @@
|
||||
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)
|
||||
}
|
Reference in New Issue
Block a user