pub struct Regex { /* private fields */ }
Expand description
An abstraction for regex patterns.
- Allows swapping out the regex implementation because it’s only in this module.
- Makes regexes serializable and deserializable using just the pattern string.
- Lazily compiles regexes on first use to improve initialization time.
Implementations§
source§impl Regex
impl Regex
sourcepub fn new(regex_str: String) -> Self
pub fn new(regex_str: String) -> Self
Create a new regex from the pattern string.
Note that the regex compilation happens on first use, which is why this method does not return a result.
sourcepub fn try_compile(
regex_str: &str
) -> Option<Box<dyn Error + Send + Sync + 'static>>
pub fn try_compile( regex_str: &str ) -> Option<Box<dyn Error + Send + Sync + 'static>>
Check whether the pattern compiles as a valid regex or not.
sourcepub fn search(
&self,
text: &str,
begin: usize,
end: usize,
region: Option<&mut Region>
) -> bool
pub fn search( &self, text: &str, begin: usize, end: usize, region: Option<&mut Region> ) -> bool
Search for the pattern in the given text from begin/end positions.
If a region is passed, it is used for storing match group positions. The argument allows
the Region
to be reused between searches, which makes a significant performance
difference.
Trait Implementations§
source§impl<'de> Deserialize<'de> for Regex
impl<'de> Deserialize<'de> for Regex
source§fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>where
D: Deserializer<'de>,
fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>where D: Deserializer<'de>,
Deserialize this value from the given Serde deserializer. Read more
source§impl PartialEq<Regex> for Regex
impl PartialEq<Regex> for Regex
impl Eq for Regex
Auto Trait Implementations§
impl RefUnwindSafe for Regex
impl Send for Regex
impl Sync for Regex
impl Unpin for Regex
impl UnwindSafe for Regex
Blanket Implementations§
source§impl<Q, K> Equivalent<K> for Qwhere
Q: Eq + ?Sized,
K: Borrow<Q> + ?Sized,
impl<Q, K> Equivalent<K> for Qwhere Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,
source§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
Compare self to
key
and return true
if they are equal.