use std::str;
use regex::bytes::{RegexBuilder, RegexSetBuilder, SetMatches, Captures};
use crate::Result;
pub trait EmailRegex {
fn search(&self, regex: &str) -> Result<bool>;
fn search_with_captures(&self, regex: &str) -> Result<Option<Captures>>;
fn search_set(&self, regex_set: &[&str]) -> Result<SetMatches>;
}
impl EmailRegex for &[u8] {
fn search(&self, regex: &str) -> Result<bool> {
Ok(
RegexBuilder::new(regex)
.multi_line(true)
.case_insensitive(true)
.build()?
.is_match(self)
)
}
fn search_with_captures(&self, regex: &str) -> Result<Option<Captures>> {
Ok(
RegexBuilder::new(regex)
.multi_line(true)
.case_insensitive(true)
.build()?
.captures(self)
)
}
fn search_set(&self, regex_set: &[&str]) -> Result<SetMatches> {
Ok(
RegexSetBuilder::new(regex_set)
.multi_line(true)
.case_insensitive(true)
.build()?
.matches(self)
)
}
}