junobuild_shared/
regex.rs

1use crate::errors::JUNO_ERROR_INVALID_REGEX;
2use regex::Regex;
3
4/// Compiles a regular expression from the given pattern string.
5///
6/// # Arguments
7///
8/// * `pattern` - A string slice that holds the regex pattern to compile.
9///
10/// # Returns
11///
12/// * `Ok(Regex)` if the pattern is valid.
13/// * `Err(String)` with a detailed error message including the `JUNO_ERROR_INVALID_REGEX` constant if compilation fails.
14pub fn build_regex(pattern: &str) -> Result<Regex, String> {
15    Regex::new(pattern).map_err(|e| format!("{} (`{}`: {})", JUNO_ERROR_INVALID_REGEX, pattern, e))
16}